Jump to content

ComputerCraft Script Problem, What's Wrong With This?


HJK148

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...