How to use variable as name of path

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

Hello,
I need use variables as name of path to image.

Something like this, but this code isn’t working:

var map = 1
var img = "res://Graphics/Maps/" + str (map) + ".jpg"
$"Map".texture.resource_path = img

How I can do this?
Thnaks a lot for answers!

:bust_in_silhouette: Reply From: felaugmar

Call $"Map".texture = load(img) instead of $"Map".texture.resource_path = img changing the resource_path will not ‘reload’ the resource for you.

:bust_in_silhouette: Reply From: Firty
var map:int = 1
var img:String = "res://Graphics/Maps/"+str(map)+".jpg"
$Map.texture = preload(img)

preload will not work if the path is not constant.

felaugmar | 2020-11-09 21:24