9 posts
Posted 10 July 2012 - 11:45 PM
help, I'm a lua-n00b. I want to make a light tooggle with my computer. so what I think I need to to that is a way for the computer to check if the redstone is on, and if it is on go to the else… i just dont know how.
-- here is where i need it to check if the redstone is on.
print "Powering lights"
wait(1)
redstone.setOutput("back",true )
else
redstone.setOutput("back",false )
end
64 posts
Posted 10 July 2012 - 11:51 PM
See here: (From this forum)
http://www.minecraft.../#entry11556908specifically:
if redstone.getInput("right",true) then –Checks if this is true (example of a comment note) redstone.setOutput("back",true) print("Turning power on!")else redstone.setOutput("back",false) print("Turning power off!")end
9 posts
Posted 11 July 2012 - 12:18 AM
I'm confused because that didnt help, every time i tried to turm them on it said Powering lights off, i noticed your first line,
if redstone.getInput("right",true)
and changed it to,
if redstone.getInput("back",true)
and that didnt work either.
I know its not a problem with my wiring because the redstone directly behind it didn't light up.
64 posts
Posted 11 July 2012 - 12:30 AM
ok your initial description / code isnt the easiest for me to understand exactly how you want it to work. Heres a sample program that works to set an output using the PC. It may help you sort it out. Write more detail if you like and ill try help.
Copy it to your ROM folder: modsComputerCraftluaromprograms
and then in a pc type
l back on
or
l back off
(Thats "l" for Luke)
[attachment=310:l.zip]
504 posts
Location
Seattle, WA
Posted 11 July 2012 - 12:38 AM
I believe the issue could be caused by the fact that your computer is the body generating the redstone pulse whereas
redstone.getInput();
is checking to see if your computer is the medium that a redstone pulse may be using.
A solution may be to use a variable to hold the state of your light.
Here's some sample code:
-- "Light toggle for Beefy547 by PaymentOption" --
bLights = false; -- "We'll start assuming that we are not generating a pulse and therefore the lights are off, or false."
sInput = ""; -- This variable will hold the user input to toggle the light.
print("Enter 'toggle' to toggle the lights.");
write("> "); sInput = read();
if sInput == "toggle" and bLights then -- "Protip: if you pass a variable name as a condition for an if statement, it will check if it is true." or false, or nil.
rs.setOutput("back", false); -- "In this case we'll check if bLights is true and change the redstone output accordingly."
elseif sInput == "toggle" and not bLights then
rs.setOutput("back", true); -- "Here, we'll check if bLights is false and change the redstone output accordingly."
else
print("nInvalid input parameter. Please try again.");
end
Feel free to edit this any way you'd like, I just hope that you understand the method I used to control the lights. B)/>/>
PS. I used ' "" ' to make my comments green in the code block :)/>/> So they're not necessary, in case you were wondering. B)/>/>
9 posts
Posted 11 July 2012 - 01:01 AM
@PaymentOption
Thanks for the help, but after using your code word for word it only turns them on and not back off.
P.S. I would prefer that just typing the program name (Lights) itself into the computer would toggle them, so I don't need to type lights the toggle every time I want to toggle the red stone lamps.
64 posts
Posted 11 July 2012 - 01:11 AM
Beefy, here is some real simple code you can understand and take further yourself:
local tArgs = { ... }
local sSide = tArgs[1] or "back" --this line means the first word after the program would alter the output side (sSide), or just use back if you dont give a side.
if redstone.getInput(sSide,true) then -- Is the sSide active now, if yes then?
redstone.setOutput( sSide, false ) -- Make it turn off
else -- else it is not active
redstone.setOutput( sSide, true ) --so turn it on
end
9 posts
Posted 11 July 2012 - 03:54 AM
@
LucasUKThanks soooo much thats exactly what I needed. And thanks for the patience from both of you, It's having people like you two on this forum that make this mod worth having to me and other people that are still learning when it comes to lua.