I've got a problem,i want my turtle to go forward a SPECIFIED (x) number of times...
I tried it like this
--Program name is: Forward ..x.. a = x while a > 0 do turtle.forward() a = a-1 end
It says: Attempt to compare nil with number
How to fix this?
Posted 12 July 2012 - 01:27 PM
--Program name is: Forward ..x.. a = x while a > 0 do turtle.forward() a = a-1 end
Posted 12 July 2012 - 01:41 PM
a = arg[1] while a > 0 do turtle.forward() a = a-1 end
Posted 12 July 2012 - 01:52 PM
local args = { ... }
That will give you an array (wich is actually a table with numeric indices) with all the arguments passed to the program. Now you can access them like:local times = args[1]but remember that the arguments are strings, so you have to convert it if you need a number:
local nTimes = tonumber(args[1])And now you can use it in a loop (I'll use a for loop since it's better for this kind of things):
for i = 1, nTimes do turtle.forward() end
Posted 12 July 2012 - 02:44 PM
MysticT, on 12 July 2012 - 01:52 PM, said:
local args = { ... }
That will give you an array (wich is actually a table with numeric indices) with all the arguments passed to the program. Now you can access them like:local times = args[1]but remember that the arguments are strings, so you have to convert it if you need a number:
local nTimes = tonumber(args[1])And now you can use it in a loop (I'll use a for loop since it's better for this kind of things):
for i = 1, nTimes do turtle.forward() end
0 members, 1 guests, 0 anonymous users