Hello all. First, sorry for the basic question but I am beginner....

My question is : How to create a variable with a dynamic name ? I used to code it in flash action-script like that : var nameid = 1 var ["variablename"+string(nameid)] = 100

it gives a variable with the name "variablename1"

But I don't know how to do it in GDscript :(

You would use "get()" and "set()" to do this.

var test32 = "this is a test"
var id = 32
set("test" + str(id), "do not use elevators")
print("output: ", test32)
var output = get("test" + str(id))
print("output: ", output)

Also, welcome to the forum! I used to be a Flash programmer too.

mmmmm..... maybe I don't understand all but it seems your solution is to fill a dynamic named variable

But, how to create it ? How to create a variable with a dynamic name ?

If I want to create a variable "test"+nb where nb is a number in a 4 boucle for example... I woud like to have 4 variables created : test1 test2 test3 test4

And then, I can fill and use these variables laster in the program

I'm not sure you can do that (unless I am missing something). But you can find other ways to save that data, for example using an Array or Dictionary.

ok, I will change my way of thinking then ;) thanks again!

3 years later

Is there a way to do this if you are trying to concatenate a variable name that will map back to '.text' on a GUI control? For example:

var test32_button = $ComponentDisplay/Component32Button;

var id = 32
set("test" + str(id) + "_button.text", "do not use elevators")

** the displayed text value of the GUI control would now be "do not use elevators"
when I try that, the displayed value of the control does not change from the default value. Thanks for any ideas.

9 days later