Clickteam Poradniki
Clickteam Poradniki

Reputation: 1

Is it possible to change variable during running of script?

Im new into lua, I have this code :

a="1"
b="2"
c=

Is it possible to somehow define c as a+b?

Upvotes: 0

Views: 260

Answers (2)

Piglet
Piglet

Reputation: 28950

What do you mean with a+b?

If you want to add the numbers in both strings and get a number simply do

c = a + b

This implicitly does

c = tonumber(a) + tonumber(b)

This only works if a and b represent numbers! Lua will convert the strings to numbers prior to calcuating the sum.

If you want the sum as a string simply do

c = tostring(a+b)

If you want to concatenate both strings use the concatenation operator ..

c = a .. b

This will result in c being "12"

Upvotes: 3

metro
metro

Reputation: 508

Yes. With:

c = a + b

The two values will be added, and 3.0 will be stored in c at runtime.

Upvotes: 0

Related Questions