Jump to content




Quick Question


  • You cannot reply to this topic
4 replies to this topic

#1 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 15 October 2012 - 03: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?

#2 lieudusty

  • Members
  • 419 posts

Posted 15 October 2012 - 04:31 AM

Don't put quotes around string?

#3 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 15 October 2012 - 04:36 AM

View Postlieudusty, on 15 October 2012 - 04:31 AM, said:

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".

#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 15 October 2012 - 04: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. :/

#5 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 15 October 2012 - 05:35 AM

View PostKingdaro, on 15 October 2012 - 04:39 AM, said:

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...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users