Jump to content

Recommended Posts

Posted

Hi guys, I've just been playing around with ComputerCraft and Redpower frames, trying to make an elevator which has multiple floors. The script I have trouble with is named 2, since that's the floor it will go to. Whenever I run the script it says '2:2 Attempt to call nil' or something.

This is the script:

print ("Going to floor [ 2 ]")

if rs.BundledOutput("bottom", 0) then

rs.BundledOutput("bottom", colors.black)

sleep (0.1)

rs.BundledOutput("bottom", 0)

sleep (1)

rs.BundledOutput("bottom", colors.black)

sleep (0.1)

rs.BundledOutput("bottom", 0)

sleep (1)

rs.BundledOutput("bottom", colors.black)

sleep (0.1)

rs.BundledOutput("bottom", 0)

sleep (1)

rs.BundledOutput("bottom", colors.black)

sleep (0.1)

rs.BundledOutput("bottom", 0)

print ("We have arrived at level [ 2 ]")

end

if not rs.BundledOutput("bottom", 0) then

rs.BundledOutput("bottom", 0)

sleep (0.1)

rs.BundledOutput("bottom", colors.black)

sleep (0.1)

rs.BundledOutput("bottom", 0)

sleep (1)

rs.BundledOutput("bottom", colors.black)

sleep (0.1)

rs.BundledOutput("bottom", 0)

sleep (1)

rs.BundledOutput("bottom", colors.black)

sleep (0.1)

rs.BundledOutput("bottom", 0)

sleep (1)

rs.BundledOutput("bottom", colors.black)

sleep (0.1)

rs.BundledOutput("bottom", 0)

print ("We have arrived at level [ 2 ]")

end

This has been fixed now, the new code is:

print ("Going to floor [ 2 ]")

if rs.testBundledInput("bottom", colors.black)==false and rs.testBundledInput("bottom", colors.white)==false then

rs.setBundledOutput("bottom", colors.black)

sleep (0.1)

rs.setBundledOutput("bottom", 0)

sleep (1)

rs.setBundledOutput("bottom", colors.black)

sleep (0.1)

rs.setBundledOutput("bottom", 0)

sleep (1)

rs.setBundledOutput("bottom", colors.black)

sleep (0.1)

rs.setBundledOutput("bottom", 0)

sleep (1)

rs.setBundledOutput("bottom", colors.black)

sleep (0.1)

rs.setBundledOutput("bottom", 0)

end

if rs.testBundledInput("bottom", colors.black)==true or rs.testBundledInput("bottom", colors.white)==true then

rs.setBundledOutput("bottom", 0)

sleep (0.1)

rs.setBundledOutput("bottom", colors.black)

sleep (0.1)

rs.setBundledOutput("bottom", 0)

sleep (1)

rs.setBundledOutput("bottom", colors.black)

sleep (0.1)

rs.setBundledOutput("bottom", 0)

sleep (1)

rs.setBundledOutput("bottom", colors.black)

sleep (0.1)

rs.setBundledOutput("bottom", 0)

sleep (1)

rs.setBundledOutput("bottom", colors.black)

sleep (0.1)

rs.setBundledOutput("bottom", 0)

end

print ("Arrived at floor [ 2 ]")

I used tabs but it doesn't seem to work with the quote format.

Posted

Thanks, I've only used Lua once before, when I used to play a game called Roblox sometime around 2006, I think I was about 9 at the time, and used to use the scripting engine. It was apparently a simplified version though.

Posted

Ok, so I added the 2 'do's at the end of the 'if' statements and it told me to add an extra 'end' after the ones on line 19 and line 40, so I added them but it still says '2:2: Attempt to call nil' when I try to use it.

Posted

I haven't programmed in LUA for a while so I am really rusty. Its just been papyrus.

Gl and Hf.

I fixed the problem, I was typing 'rs.BundledOutput("bottom", colors.black)' instead of 'rs.setBundledOutput("bottom", colors.black)' for all of the commands. Also I've replaced the 2nd and 20th lines with this format 'if rs.testBundledInput("bottom", colors.black)==false and rs.testBundledInput("bottom", colors.white)==false then'. I haven't tested it but I think it should work properly now.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...