HJK148 Posted January 8, 2013 Posted January 8, 2013 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.
disconsented Posted January 8, 2013 Posted January 8, 2013 You need to have "do" at the end of your if statements IIRC. Also learn to indent, it makes reading (and consequently debugging) easier.
HJK148 Posted January 8, 2013 Author Posted January 8, 2013 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.
HJK148 Posted January 8, 2013 Author Posted January 8, 2013 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.
disconsented Posted January 8, 2013 Posted January 8, 2013 Nvm about do but your problem is you are asking the computer a command instead of asking if you are getting input on the side you want redstone.getInput("bottom")
HJK148 Posted January 8, 2013 Author Posted January 8, 2013 Thanks, never would have thought about that. At least one of us has a brian!
disconsented Posted January 8, 2013 Posted January 8, 2013 I haven't programmed in LUA for a while so I am really rusty. Its just been papyrus. Gl and Hf.
HJK148 Posted January 11, 2013 Author Posted January 11, 2013 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now