How to combine variables? [SOLVED]

I mean as in like:
(Variable) + (Variable2) —> VariableVariable2
How can i do this?

Go in to variable editor and type “VariableVariable2” :stuck_out_tongue:

But for real, no, you can’t do that. If you really need to then what you could do is have a structure with your named elements, so that you can access them via string. Then to access a “combined” variable you could add the strings together:

someStructure[string1 + string2]

My question is, why?

Savefile stuff for game

Also im using numbers not strings

like if the variables were 6 and 3 i want the result to be 63 not 9

Yes, you can add strings together (also known as concatenate) which will result in a new string:

“bob” + “cat” = “bobcat”

In some cases you can even use a number in the concatenation and GDevelop will automatically use it as a string, as in

"Value of x = " + x
(x is a number variable).

This doesn’t always work though, in which case you’ll need ToString(variable) to convert the number.

VarA = 6
VarB = 3

In text object
ToString(VarA)+ToString(VarB)

Result 63

In equation
(VarA*10)+VarB

Result 63

1 Like

thank you it worked!!

1 Like