Variable name from another variable

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Eidam

I´m looking the way, how I can create or refer to variable using another variable…
Something as:

var number = 1
var ("variable"+str(number)) = 0

Can it be done in Godot? And how?
Thank you for your help!

:bust_in_silhouette: Reply From: A112

You could achieve that effect using dictionaries:

extends Node2D
var dict={
func _ready():
var x =2
var y = "a"

You can also add your own variables to a dictionary, just refer to it’s name and assign a value

Thanks for your answer!
She helped me a lot!

Eidam | 2020-05-05 19:45

I’m glad I could help :slight_smile:

A112 | 2020-05-05 22:07