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

Table strings to numbers

Started by masterdisasterHD, 18 June 2013 - 01:27 AM
masterdisasterHD #1
Posted 18 June 2013 - 03:27 AM
My question:

I made a program which uses arguments to run
If i run it like: program do setPos 1 1

Everything is a string but how do i convert those 1's back to numbers no matter where it is in the table?

for i,v in ipairs(tArgs) do
A = type(tArgs)
end
( type(tArgs) returns string )
1lann #2
Posted 18 June 2013 - 05:35 AM

local newArgs = {}
for k,v in ipairs(tArgs) do
if tonumber(v) then
  newArgs[k] = tonumber(v)
else
newArgs[k] = v
end
-- Use newArgs
masterdisasterHD #3
Posted 18 June 2013 - 06:17 AM
Thanks man issue solved :D/>