Jump to content




Need some help 'end' expected (to close 'while' at line 3)


7 replies to this topic

#1 cjgreenwood

  • New Members
  • 4 posts

Posted 26 October 2012 - 01: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).
Attached File  lift programming.rtf   530bytes   166 downloads
Any help would be greatly appreciated.

#2 unknown1138

  • New Members
  • 11 posts

Posted 26 October 2012 - 01: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.

#3 cjgreenwood

  • New Members
  • 4 posts

Posted 26 October 2012 - 01: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

#4 unknown1138

  • New Members
  • 11 posts

Posted 26 October 2012 - 01:20 PM

Post your whole script or tell me what you want your script to do

#5 cjgreenwood

  • New Members
  • 4 posts

Posted 26 October 2012 - 01: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

#6 unknown1138

  • New Members
  • 11 posts

Posted 26 October 2012 - 01: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/>

#7 Ditto8353

  • New Members
  • 138 posts

Posted 26 October 2012 - 01: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'

#8 cjgreenwood

  • New Members
  • 4 posts

Posted 26 October 2012 - 01:39 PM

ah brilliant that works perfectly thanks alot! :D/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users