Scripts / Changing types in lua

Author
Message
TazMan
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 20th Jan 2011
Location: Worldwide Web
Posted: 11th Jan 2016 13:02
Hello everyone.

Has anyone got any idea how to change a String type to an Integer type im LUA or Visa Versa. I would like to change a String into an Integer so that I can then times them together, but I can work with strings if that is not possible yet. Thanks

HP Pavilion Laptop, AMD A8-4555M APU with Radeon(tm) Graphics HD Graphics 1.6GHz, 8GB Memory, 64 Bit Operating System (Windows 10), 1 TB Hard Drive.

I've got something to say - It's better to burn out than fade away.
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 11th Jan 2016 13:14 Edited at: 11th Jan 2016 13:14
Quote: "tonumber (e [, base])

When called with no base, tonumber tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.

The conversion of strings can result in integers or floats, according to the lexical conventions of Lua (see ยง3.1). (The string may have leading and trailing spaces and a sign.)"


Quote: "When called with base, then e must be a string to be interpreted as an integer numeral in that base. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. If the string e is not a valid numeral in the given base, the function returns nil.

tostring (v)

Receives a value of any type and converts it to a string in a human-readable format. (For complete control of how numbers are converted, use string.format.)
If the metatable of v has a "__tostring" field, then tostring calls the corresponding value with v as argument, and uses the result of the call as its result."


Source: http://www.lua.org/manual/5.3/manual.html#pdf-tostring

hth

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
TazMan
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 20th Jan 2011
Location: Worldwide Web
Posted: 12th Jan 2016 09:28
Thanks 3com, these work perfectly. I had found this out previously but when I tried it in my code it did not work, I just tried them both out individualy and they obviously do work. It must have been something else affecting them before.
HP Pavilion Laptop, AMD A8-4555M APU with Radeon(tm) Graphics HD Graphics 1.6GHz, 8GB Memory, 64 Bit Operating System (Windows 10), 1 TB Hard Drive.

I've got something to say - It's better to burn out than fade away.

Login to post a reply

Server time is: 2024-12-22 12:06:42
Your offset time is: 2024-12-22 12:06:42