4 posts
Posted 25 December 2015 - 12:36 PM
Hi!
I m new to programming, i made some simple programs in lua and works, special redstone timers for rotarycraft and pneumaticraft, also basics mining.
Now i want to make a menu for control a launchpod for Galacticraft, my problem is the litte program i make for control the "launch hatch door" dont work, keeps forever rs signal turn on, i try whit "goto" command, but it not exits or works anymore also my other programs whit goto are in other pc and i cant acces for read what i do in then.
Here is the scrip:
local close –for later use
local oc = "no"
function op()
rs.setOutput("right", false)
sleep(5) –it should be 30, but i m testing
end
function cl()
rs.setOutput("right", true)
sleep(1)
end
cl() – i call 1st for keep the hatch close at 1st run
while true do
term.clear()
term.setCursorPos(1,1)
print("Launchpod controller")
term.setCursorPos(1,2)
print("Open Launchpad?")
term.setCursorPos(1,3)
print("[Yes/No]")
term.setCursorPos(1,4)
oc = read()
if oc == yes then –this donsent run, not clear screen, no print message, no run function to open door
term.clear()
print("open hatch 30 seg to launch")
op()
cl()
else
cl()
end
end
regarless i put "yes" the program still whit "rs.setOutput("right", true)" true, looks like it dont call function for turn if off and open the door.
the program is unfinish i want to add more things later, but i need 1st make this works for futher, that means is in test progress.
i look menus tutorial, but theri is so many i get confused and dont know what to do to solve, i know its simple, but i m not a programmer, pls help.
Thanks a lot and sorry for my bad english.
4 posts
Posted 23 January 2016 - 05:43 AM
i have not used read() yeb but i assume it returns a string when you press enter. in that case the yes in the if statment sould be on quotes. otherwise it looks for the varible named yes wich probably has a nil value so the if is never true
29 posts
Posted 23 January 2016 - 08:04 AM
Hi!
I m new to programming, i made some simple programs in lua and works, special redstone timers for rotarycraft and pneumaticraft, also basics mining.
Now i want to make a menu for control a launchpod for Galacticraft, my problem is the litte program i make for control the "launch hatch door" dont work, keeps forever rs signal turn on, i try whit "goto" command, but it not exits or works anymore also my other programs whit goto are in other pc and i cant acces for read what i do in then.
It seems for starters that the functions in the beginning of the program run without being called. It also seems likely that you're over complicating the whole program - which isn't a bad thing. It seems that you've also switched the
op() cl() functions, assuming
op() is open and
cl() is close. I don't currently have the ability to test galacticraft, so you'll just have to let me know. You're also running
op() and
cl() right after each other, giving whoever wants to enter the pod an impossible amount of time to enter it. Other than that, the menu is fine.
--term.clear() -These are optional, it might be better not to include them
--term.setCursorPos(1,1)
x = true
print("Launchpod Control")
print("To open type Open")
print("To close type Close")
print("Type anything to exit")
print("---------------------")
while x do
input = read()
if input == "open" then
print("Door Open")
redstone.setOutput("right", true)
elseif input == "close" then
print("Door Closed")
redstone.setOutput("right", false)
else
print("Goodbye!")
x = false
end
end
Download the file via pastebin
pasetbin get tWeYA1Kd
That should be a more simplified version. Reply if you have anymore questions.
957 posts
Location
Web Development
Posted 23 January 2016 - 08:06 AM
Like jotacraft said, you need to put 'yes' in quotes, like this:
if oc == "yes" then
1080 posts
Location
In the Matrix
Posted 23 January 2016 - 08:26 PM
–snip– You're also running op() and cl() right after each other, giving whoever wants to enter the pod an impossible amount of time to enter it.–Snip–
Read the functions, they have sleep in them, he's good. The only issue he was running into, what was webcam said and jotacraft said, you need the quotes around yes so they're strings and not nil.
Try not to just ignore the problem that someone is having and code them up an instant solution that doesn't fit their entire criteria.
Edited on 23 January 2016 - 07:28 PM
2427 posts
Location
UK
Posted 23 January 2016 - 08:48 PM
i have not used read() yeb but i assume it returns a string when you press enter. in that case the yes in the if statment sould be on quotes. otherwise it looks for the varible named yes wich probably has a nil value so the if is never true
Let me try to explain this a bit clearer.
@OP You have correctly identified the line which is causing the problem and as Dragon said, both webcam and jotacraft have given the correct solution.
But let me give you a peak into what lua is doing when it reads this line in your code
if oc == yes then
So oc is your input variable, not very clearly named but that is not the issue. The problem is the yes. To lua this is a variable, do when it reads
if oc == yes then
it looks for a variable in your program called oc and finds it. Lua then looks for a variable called yes and doesn't find it so yes is equal to nil (or null in other languages), which basically means yes has no value. You input variable (oc) will always have a variable, even if you didn't type anything (you will get an empty string in this case). As the people above me have said, you want lua to check oc against a literal yes, which is done like so.
if oc == "yes" then
Now lua compares oc against the value of "yes" where as before it was comparing oc against a non-existent variable called yes.
Edited on 23 January 2016 - 07:49 PM
4 posts
Posted 06 December 2017 - 02:09 PM
Hello!! here is my program fixed.
local Option = ""
local Run = true
function Open()
rs.setOutput("right", false)
rs.setOutput("left", true)
sleep(0.5)
end
function Close()
rs.setOutput("right", true)
rs.setOutput("left", false)
sleep(0.5)
end
function Menu()
term.clear()
term.setCursorPos(1,1)
print("Launchpod controller")
term.setCursorPos(1,2)
print("Open Launchpad?")
term.setCursorPos(1,3)
print("[yes/no/exit]")
term.setCursorPos(1,4)
Option = read()
if Option == "yes" then
Open()
sleep(30)
Close()
elseif Option == "no" then
Close()
sleep(0.1)
elseif Option == "exit" then
Exit()
sleep(0.1)
end
end
function Exit()
rs.setOutput("right", false)
rs.setOutput("left", false)
sleep(0.1)
Run = false
end
Close() -- i call 1st for keep the hatch close at 1st run
while Run do
Menu()
end
Now it opens and close afther 30 seg. so, you have 30 to launch the galacticraft rokect, t have 20 seg to launch. hope someone enjoy it, as for my aat least i have a hard backup here XD, if i improve the code i reupload it.
Have a nice chrismas!
Forget to say, the letf rsw signal is for one insdustrialcraft 2 alarm. so its pretty cool opening the hatch for launch and a siren sound "meccc, meeecc" while the door is open.