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

Variables input by a user

Started by EpicTreeMiner, 11 January 2013 - 10:58 PM
EpicTreeMiner #1
Posted 11 January 2013 - 11:58 PM
I have been stumped with this problem.
Have made a turtle that builds a circular tower, it all works fine and it is now a function, but I want it to loop a set amount of times, not infinitely. The amount however, I want to be input by a user. So say what the user types is 10 , x = 10
So it would be
for I = 1,x
Function circleLoop()
End

Please help, also, I feel rut has something to do with arguments
theoriginalbit #2
Posted 12 January 2013 - 12:01 AM
input in-program:

local timesLoop = tonumber( read() )

input from command line arguments

local args = { ... }
local timesLoop = tonumber( args[1] )
EpicTreeMiner #3
Posted 12 January 2013 - 12:15 AM
input in-program:

local timesLoop = tonumber( read() )

input from command line arguments

local args = { ... }
local timesLoop = tonumber( args[1] )

Could you please explain more, if I post the code could you sow me where to put it?
theoriginalbit #4
Posted 12 January 2013 - 12:24 AM
tonumber() converts the input string into a number
read() takes input from the user and won't continue until they press enter

local args = { … } is creating a table of the runtime arguments and storing it in the args variable
args[1] is accessing the first element in the table.

which one would you prefer to use?
EpicTreeMiner #5
Posted 12 January 2013 - 01:32 AM
tonumber() converts the input string into a number
read() takes input from the user and won't continue until they press enter

local args = { … } is creating a table of the runtime arguments and storing it in the args variable
args[1] is accessing the first element in the table.

which one would you prefer to use?

Tonumber, thank you so much