This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Pants's profile picture

Help with tunnel program

Started by Pants, 19 June 2013 - 08:50 PM
Pants #1
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/PAu23Sfk
it 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
Lyqyd #2
Posted 19 June 2013 - 11:31 PM
Split into new topic.
Bomb Bloke #3
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.
Engineer #4
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
TheOddByte #5
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)
Engineer #6
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
TheOddByte #7
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 :)/>
theoriginalbit #8
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…
Engineer #9
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/>
skydude92 #10
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.