4 posts
Posted 26 October 2012 - 02:08 PM
Hey i've been having a bit of trouble with my lift design. I keep getting this problem error [string 'startup']:8: 'end' expected (to close 'while' at line 3).
[attachment=622:lift programming.rtf]
Any help would be greatly appreciated.
11 posts
Posted 26 October 2012 - 02:11 PM
x = 13
if rs.getInput("top") then
while x >= 0 do
rs.setOutput("left", true)
sleep(0.5)
rs.setOutput("left", false)
sleep(0.5)
return x = x - 1
else os.reboot()
end
end
Please use code tags next time :D/>/>
The problem is that you are using an else while there is no if, you can't do that.
4 posts
Posted 26 October 2012 - 02:18 PM
Yea sorry about that i'm new to this forum :D/>/>
I've tried it without the else and with a repeat instead of the while and it gives the same error
11 posts
Posted 26 October 2012 - 02:20 PM
Post your whole script or tell me what you want your script to do
4 posts
Posted 26 October 2012 - 02:25 PM
That is the whole script as of now. Basically when i press a button i want it to trigger the lift to take me down thirteen floors. Im starting to think tht maybe a repeat-until function would be more useful.
x = 13
if rs.getInput("top") then
repeat
rs.setOutput("left", true)
sleep(0.5)
rs.setOutput("left", false)
sleep(0.5)
return x = x - 1
until x == 0
end
But this gives me 'until' expected to close 'repeat' at line 3
11 posts
Posted 26 October 2012 - 02:30 PM
x = 0
if rs.getInput("top") then
while x ~= 13 do
rs.setOutput("left",true)
sleep(0.5)
rs.setOutput("left",false)
sleep(0.5)
x = x+1
end
end
I think this script will do the trick :D/>/>
136 posts
Posted 26 October 2012 - 02:31 PM
x = 13
if rs.getInput("top") then
for i=1,x do
rs.setOutput("left",true)
sleep(0.5)
rs.setOutput("left",false)
sleep(0.5)
end
end
If you don't actually plan on using 'x' to collect an input, then remove 'x = 13' and then change 'for i=1,x do' to 'for i=1,13 do'
4 posts
Posted 26 October 2012 - 02:39 PM
ah brilliant that works perfectly thanks alot! :D/>/>