This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kaffefilter's profile picture

[Lua] How to lights active

Started by kaffefilter, 06 April 2012 - 01:18 AM
kaffefilter #1
Posted 06 April 2012 - 03:18 AM
Hey there.

So, yesterday I decided to take up CC and lua, though as I'm still new to it all, I have a hard time googling everything, as I dont even know what to google for :/

Anyway, I'm building a tiny test system to evolve my skill base on.
Basicly, I've added 2 levers, and 4 lights, 1 lever pr 2 lights. on/off.
However, the lights are flashing, and I do not know how to "lock" each light and keep 2 active at the same time.

Heres my code:
pastebin
Spoilerwhile true do
event, param = os.pullEvent()
if event == "redstone" and rs.testBundledInput("front", colors.white) == true then
rs.setBundledOutput("back", colors.green)
term.clear()
term.setCursorPos(1,1)
print("..Green light on - Lever on (white index)")
elseif rs.testBundledInput("front", colors.white) == false then
rs.setBundledOutput("back", colors.lime)
term.clear()
term.setCursorPos(1,1)
print("..Lime light on - Lever off")
end
event, param = os.pullEvent()
if event == "redstone" and rs.testBundledInput("front", colors.blue) == true then
rs.setBundledOutput("back", colors.red)
term.clear()
term.setCursorPos(1,1)
print("..Red light on - Lever on (blue index)")
elseif rs.testBundledInput("front", colors.blue) == false then
rs.setBundledOutput("back", colors.gray)
term.clear()
term.setCursorPos(1,1)
print("..Gray light on - Lever off")
end
end

Hope you guys can help me :)/>/>

best regard
kaffe
Luanub #2
Posted 06 April 2012 - 11:55 AM
You need to use a variable for the colors in the rs.setBundledOutput() statements while using the color api to add/remove the colors from the var thus putting them in an on or off state when the set command is run.

This should fix it.
Spoiler

local c = colors.combine( c )

while true do
event, param = os.pullEvent()
if event == "redstone" and rs.testBundledInput("front", colors.white) == true then
c = colors.combine( c, colors.green ) -- this will set green to be on
c = colors.subtract( c, colors.lime )  -- this will set lime to be off
rs.setBundledOutput("back", c ) -- this actions the above
term.clear()
term.setCursorPos(1,1)
print("..Green light on - Lever on (white index)")
elseif rs.testBundledInput("front", colors.white) == false then
c = colors.combine( c, colors.lime ) -- opposite from above
c = colors.subtract( c, colors.green )
rs.setBundledOutput("back", c )
term.clear()
term.setCursorPos(1,1)
print("..Lime light on - Lever off")
end
event, param = os.pullEvent()
if event == "redstone" and rs.testBundledInput("front", colors.blue) == true then
c = colors.combine( c, colors.red ) -- same thing as above
c = colors.subtract( c, colors.gray )
rs.setBundledOutput("back", c )
term.clear()
term.setCursorPos(1,1)
print("..Red light on - Lever on (blue index)")
elseif rs.testBundledInput("front", colors.blue) == false then
c = colors.combine( c, colors.gray ) -- and again
c = colors.subtract( c, colors.red )
rs.setBundledOutput("back", c )
term.clear()
term.setCursorPos(1,1)
print("..Gray light on - Lever off")
end
end

Type help redpower from a terminal for some info on this.
djblocksaway #3
Posted 06 April 2012 - 12:45 PM
You need to use a variable for the colors in the rs.setBundledOutput() statements while using the color api to add/remove the colors from the var thus putting them in an on or off state when the set command is run.

This should fix it.
Spoiler

local c = colors.combine( c )

while true do
event, param = os.pullEvent()
if event == "redstone" and rs.testBundledInput("front", colors.white) == true then
c = colors.combine( c, colors.green ) -- this will set green to be on
c = colors.subtract( c, colors.lime )  -- this will set lime to be off
rs.setBundledOutput("back", c ) -- this actions the above
term.clear()
term.setCursorPos(1,1)
print("..Green light on - Lever on (white index)")
elseif rs.testBundledInput("front", colors.white) == false then
c = colors.combine( c, colors.lime ) -- opposite from above
c = colors.subtract( c, colors.green )
rs.setBundledOutput("back", c )
term.clear()
term.setCursorPos(1,1)
print("..Lime light on - Lever off")
end
event, param = os.pullEvent()
if event == "redstone" and rs.testBundledInput("front", colors.blue) == true then
c = colors.combine( c, colors.red ) -- same thing as above
c = colors.subtract( c, colors.gray )
rs.setBundledOutput("back", c )
term.clear()
term.setCursorPos(1,1)
print("..Red light on - Lever on (blue index)")
elseif rs.testBundledInput("front", colors.blue) == false then
c = colors.combine( c, colors.gray ) -- and again
c = colors.subtract( c, colors.red )
rs.setBundledOutput("back", c )
term.clear()
term.setCursorPos(1,1)
print("..Gray light on - Lever off")
end
end

Type help redpower from a terminal for some info on this.
or if your useing just plain redstone or red alloy wire (redpower feature) than use
rs.setOutput("side",true) –Change side to the side the redstone is
kaffefilter #4
Posted 06 April 2012 - 03:55 PM
Thanks for the answers :)/>/> Going to work around from the code you posted luanub:)