Use String in variable calling

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

Hello i am trying to access a object in another script using a variable name.
The GameData contains a set of var ranging form road0 to road20, which hold a iconTexture. The code needs to get the texture of a certain var depending on a determent number. What i have:

func temp():
    var nmr = 1
    var roadnmr = "road"+str(nmr)
    sprite.texture = GameData.roadnmr.iconTexture

I tried changing it to dictionary or use square brackets but nothing seems to obtain the desired result.

The input number is normaly obtained by a unrelated function.

:bust_in_silhouette: Reply From: PepijnWe

Found the solution:

 func temp():
        var nmr = 1
        var roadnmr = "road"+str(nmr)
        sprite.texture = GameData.get(roadnmr).iconTexture