Product Chat (Early Access) / Convert String Functions?

Author
Message
puzzle20
1
Years of Service
User Offline
Joined: 22nd Jan 2023
Location:
Posted: 10th Nov 2023 07:56
How? I don't know much about programming and can't find in the help .
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 10th Nov 2023 09:47
You'll have to give me a little more to go on than that!

The Lua library to manipulate strings is called, amazingly enough, the strings library.

https://www.lua.org/pil/20.html

If you have a numerical string and want to reliably use it in maths use tonumber() to convert it to a number type, if it isn't actually a valid number though that will just cause an error. In most simple cases Lua will quite happily do the conversions either way itself though.

For example if you have:
local a = 10
local b = "cat"
local c = b .. a

Then c will be the string "cat10"

Similarly:
local a = "5.0"
local b = 1
local c = a + b

will usually result in c being the number 1.5 but to be safer use:

local c = tonumber( a ) + b

If otoh you actually want a string result then you can do tostring( c ).
Been there, done that, got all the T-Shirts!
PM
puzzle20
1
Years of Service
User Offline
Joined: 22nd Jan 2023
Location:
Posted: 15th Nov 2023 03:57
Thank you. Hours trying to find convert functions in the auto complete.
PM
puzzle20
1
Years of Service
User Offline
Joined: 22nd Jan 2023
Location:
Posted: 4th Dec 2023 22:27
How do i execute lua in agk? Hundreds of hours in this so far.
PM

Login to post a reply

Server time is: 2024-05-11 05:57:58
Your offset time is: 2024-05-11 05:57:58