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

Quick Question

Started by brett122798, 15 October 2012 - 02:43 AM
brett122798 #1
Posted 15 October 2012 - 04:43 AM
Okay, I'm trying to make an automatic converter(int to string and string to int), so here's one of the functions:


function intstring(name)
(name.."string") = tostring(name) -- Errors Here
end

I guess (name.."string") is the problem, but how can I revise this to fix the error?
lieudusty #2
Posted 15 October 2012 - 05:31 AM
Don't put quotes around string?
brett122798 #3
Posted 15 October 2012 - 05:36 AM
Don't put quotes around string?
No, I need that, like here's what I need it like:

You enter


test = 5
intstring(test)

And you get "teststring".
Kingdaro #4
Posted 15 October 2012 - 05:39 AM
The way you're doing it is kind of "what are you even doing I don't understand this shouldn't even be possible".

You should probably just check to see if it's an integer or string first before converting.

function intstring(var)
if type(var) == 'string' then
  return math.floor(tonumber(var)) -- math.floor so there are no decimals
elseif type(var == 'number' then
  return tostring(var)
end
end

…Unless this isn't what you're trying to do. :/
JoshhT #5
Posted 15 October 2012 - 06:35 AM
The way you're doing it is kind of "what are you even doing I don't understand this shouldn't even be possible".

This amused me :D/>/>

But I agree with you, OP has me confused…