12 posts
Posted 17 January 2013 - 04:23 PM
hello there,
I need some help with a program I just wrote. (lift)
Here it is :
http://pastebin.com/dpzeVWDVAt the very bottom, where it tries to find the number of times to move up or down, it come up with the error: lift:82: attempt to compare nil with number.
I am pretty sure both variables are defined ( lines 63 - 76 and 49 )
but it tells me one of them = nil,
BTW: at every Floor there is a redpower clolored insulated wire that is on so that it knows that floor it is on.
can someone please help, thanks
kingcoon.
174 posts
Posted 17 January 2013 - 04:38 PM
Because the error is happening on line 82 and yet you have line 80 calling your currentFloor variable then I can only assume that the issue is how you are setting your toFloor variable as a number.
Not sure if this will fix it but instead of this:
term.setCursorPos(3,4)
write("Requested Floor:")
toFloor = io.read()
term.clear()
term.setCursorPos(1,1)
print("Going to Floor ", toFloor)
try this:
term.setCursorPos(3,4)
write("Requested Floor:")
toFloor =toNumber( io.read())
term.clear()
term.setCursorPos(1,1)
print("Going to Floor ", toFloor)
and remove the number conversion down on line 60
12 posts
Posted 17 January 2013 - 04:44 PM
yea i did try that, before.
i have read over it more and I am pretty sure the variable that is nil is currentFloor, because when it is printed it doesn't come up with anything:::
print("Current Floor: ", currentFloor)
it shows
" Current Floor: "
so i think that one is then problem. but thanks anyway
7508 posts
Location
Australia
Posted 17 January 2013 - 04:45 PM
line 61 is the problem… you have a typo
"cunnretFloor"
174 posts
Posted 17 January 2013 - 04:45 PM
yea i did try that, before.
i have read over it more and I am pretty sure the variable that is nil is currentFloor, because when it is printed it doesn't come up with anything:::
print("Current Floor: ", currentFloor)
it shows
" Current Floor: "
so i think that one is then problem. but thanks anyway
Mind if i copy your code and test it?
174 posts
Posted 17 January 2013 - 04:47 PM
line 61 is the problem… you have a typo
"cunnretFloor"
How did i miss that?! *facepalms*
7508 posts
Location
Australia
Posted 17 January 2013 - 04:47 PM
Mind if i copy your code and test it?
Wow your nice… asking if you can copy the code to help him :P/> Man how many ppl would have to wait so much longer if I asked then had to wait for a response :P/>
line 61 is the problem… you have a typo
"cunnretFloor"
How did i miss that?! *facepalms*
Lol… anyone could have missed it… its not hard
174 posts
Posted 17 January 2013 - 04:48 PM
Mind if i copy your code and test it?
Wow your nice… asking if you can copy the code to help him :P/>/> Man how many ppl would have to wait so much longer if I asked then had to wait for a response :P/>/>
line 61 is the problem… you have a typo
"cunnretFloor"
How did i miss that?! *facepalms*
Lol… anyone could have missed it… its not hard
Nya~ :P/>
12 posts
Posted 17 January 2013 - 04:54 PM
yea sure try it if you want, i used frames (red-power) for the lift and may be posting a video on YouTube (kingcoon14) soon with the finished product.
BTW: the one that is posted on here, the moving mechanics don't work at all, i still have to work that out
thanks for the help, i looked over it 100+ times and completely missed the typo (n's do look a little like r's), thank-you.
1852 posts
Location
Sweden
Posted 19 January 2013 - 06:34 AM
You should also change when you print this:
[color=#000000]term[/color][color=#666600].[/color][color=#000000]setCursorPos[/color][color=#666600]([/color][color=#006666]3[/color][color=#666600],[/color][color=#006666]4[/color][color=#666600])[/color][color=#000000]
write[/color][color=#666600]([/color][color=#008800]"Requested Floor:"[/color][color=#666600])[/color]
[color=#000000] toFloor [/color][color=#666600]=[/color][color=#000000] io[/color][color=#666600].[/color][color=#000000]read[/color][color=#666600]()[/color]
[color=#000000] term[/color][color=#666600].[/color][color=#000000]clear[/color][color=#666600]()[/color]
[color=#000000] term[/color][color=#666600].[/color][color=#000000]setCursorPos[/color][color=#666600]([/color][color=#006666]1[/color][color=#666600],[/color][color=#006666]1[/color][color=#666600])[/color]
[color=#000000] [/color][color=#000088]print[/color][color=#666600]([/color][color=#008800]"Going to Floor "[/color][color=#666600],[/color][color=#000000] toFloor[/color][color=#666600])[/color]
To this
[color=#000000]term[/color][color=#666600].[/color][color=#000000]setCursorPos[/color][color=#666600]([/color][color=#006666]3[/color][color=#666600],[/color][color=#006666]4[/color][color=#666600])[/color][color=#000000]
write[/color][color=#666600]([/color][color=#008800]"Requested Floor:"[/color][color=#666600])[/color]
[color=#000000] toFloor [/color][color=#666600]=[/color][color=#000000] io[/color][color=#666600].[/color][color=#000000]read[/color][color=#666600]()[/color]
[color=#000000] term[/color][color=#666600].[/color][color=#000000]clear[/color][color=#666600]()[/color]
[color=#000000] term[/color][color=#666600].[/color][color=#000000]setCursorPos[/color][color=#666600]([/color][color=#006666]1[/color][color=#666600],[/color][color=#006666]1[/color][color=#666600])[/color]
[color=#000000] [/color][color=#000088]print[/color][color=#666600]([/color][color=#008800]"Going to Floor "[/color][color="#666600"]..[/color][color=#000000]toFloor[/color][color=#666600])[/color]
I don't know if it works when you use (print("Going to Floor ", toFloor)
Maybe it does but I always use (..)
2088 posts
Location
South Africa
Posted 19 January 2013 - 07:17 AM
Hellkid98, you may want to right-click, paste as Plain Text before using CTRL + V next time :P/>
1852 posts
Location
Sweden
Posted 19 January 2013 - 07:48 AM
Sorry did mean to edit that but then my internet was pretty f#%ked up for a while so I could'nt edit that,
And what I did mean to write was that
print("Going to Floor", toFloor)
Maybe should be
print("Going to Floor "..toFloor)
Sorry but I can still not edit that post since I can not seem to edit any posts on this topic since It's just loading a long time and nothing happens.(Works fine on any other topic!)
7508 posts
Location
Australia
Posted 19 January 2013 - 12:42 PM
Also there is a little remove styles button on the formatting tool bar, it looks like a eraser.
EDIT: and from what I remember print is defined like this
print( ... )
and then does an internal concat of all the parameters…