Why won't get this work? (set_texture error)

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

Hi again. sorry if I’m a bother.

Here I’m working on an instance script that can load a background based on a global script variable, changing the variable will have one of two images load.

I keep getting a string to object error… what am I doing wrong?

loader = "res://Core/Battle/Resources/Winner/"+Prebattle.Enemy["EName"]+".png"
if Global.HLevel < 2:
	temp = "H"+Prebattle.Enemy["EName"]
	loader = "res://Core/Battle/Resources/Winner/"+temp+".png"
	print(temp)
get_node("Win2").set_texture("loader")

please help!

I tried using image = load(loader) and got the same error.

Mystile1369 | 2018-03-22 13:43

:bust_in_silhouette: Reply From: Bartosz

you are setting texture to string and ofcourse it doesn’t work:

get_node("Win2").set_texture("loader")

you should use actual Texture, which can be loaded using load method documentation

Thanks Bartosz!

Please bear with me. I am new. Haven’t been working with this all that long to be honest. I love this site because almost all of the time I can find the answers to whatever questions I have by just looking. Sometimes I have to ask, and nice people like you remind me that sometimes… the answer is the simplest. Here’s what I ended up doing.

In my preloading script I added the following:
Prebattle.Win1 = load(“res://Core/Battle/Resources/Winner/Ferail.png”)
Prebattle.Win2 = load(“res://Core/Battle/Resources/Winner/HFerail.png”)
then I rewrote my call like this:
loadA = Prebattle.Win1
loadB = Prebattle.Win2
if Global.HLevel < 2:
get_node(“Win2”).set_texture(loadA)
else:
get_node(“Win2”).set_texture(loadB)

and it works!

thanks again!

Mystile1369 | 2018-03-23 01:29