1 posts
Posted 19 June 2013 - 10:50 PM
So Im trying to make a program (my first) for a 3x3 tunnel but i need some help.
so this is my code :
http://pastebin.com/PAu23Sfkit wont run and also im not sure if itll get stuck
fuel goes in first slot
enderchest for items in second slot
and enderchest in third slot for fuel.
Please Help :D/>
and also tell me what i did wrong so i understand or how to make it simpler
8543 posts
Posted 19 June 2013 - 11:31 PM
Split into new topic.
7083 posts
Location
Tasmania (AU)
Posted 19 June 2013 - 11:38 PM
"read()" returns a string, that is to say, a set of characters (or words). You want to convert it to a number, so change line 54 to:
far = tonumber(read())
It'll still have issues if the user doesn't type a number, and there may be other problems with the program as well. Explain what happens when you run it if you're still having issues.
1522 posts
Location
The Netherlands
Posted 20 June 2013 - 08:04 AM
"read()" returns a string, that is to say, a set of characters (or words). You want to convert it to a number, so change line 54 to:
far = tonumber(read())
It'll still have issues if the user doesn't type a number, and there may be other problems with the program as well. Explain what happens when you run it if you're still having issues.
To put some 'security' in, to make it always a number:
local numb = nil
repeat
numb = tonumber(read())
until numb
1852 posts
Location
Sweden
Posted 21 June 2013 - 11:57 AM
"read()" returns a string, that is to say, a set of characters (or words). You want to convert it to a number, so change line 54 to:
far = tonumber(read())
It'll still have issues if the user doesn't type a number, and there may be other problems with the program as well. Explain what happens when you run it if you're still having issues.
To put some 'security' in, to make it always a number:
local numb = nil
repeat
numb = tonumber(read())
until numb
Or just
repeat
num = tonumber(read() )
until tonumber(num)
1522 posts
Location
The Netherlands
Posted 21 June 2013 - 02:07 PM
Or just
repeat
num = tonumber(read() )
until tonumber(num)
Sure, it will work. But it wont be local. And I believe making as much variables as possible local
1852 posts
Location
Sweden
Posted 21 June 2013 - 02:56 PM
Or just
repeat
num = tonumber(read() )
until tonumber(num)
Sure, it will work. But it wont be local. And I believe making as much variables as possible local
But wouldn't this work then?
repeat
local num = tonumber(read() )
until tonumber(num)
Then it's local :)/>
7508 posts
Location
Australia
Posted 21 June 2013 - 03:02 PM
But wouldn't this work then?
repeat
local num = tonumber(read() )
until tonumber(num)
Then it's local :)/>
No because it means that it is local to the loop, so the minute the loop is exited, it forgets about it…
1522 posts
Location
The Netherlands
Posted 21 June 2013 - 03:02 PM
Or just
repeat
num = tonumber(read() )
until tonumber(num)
Sure, it will work. But it wont be local. And I believe making as much variables as possible local
But wouldn't this work then?
repeat
local num = tonumber(read() )
until tonumber(num)
Then it's local :)/>
Please test this piece of code:
repeat
local numb = tonumber(read())
until tonumber(numb)
print(numb)
Numb does not exist in the main block :P/>
12 posts
Posted 21 June 2013 - 05:08 PM
http://pastebin.com/5SHTGqUN here is a modified version of what you want, put comments in to try and clarify what i did.