Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | antoinor | |
Old Version | Published before Godot 3 was released. |
Hi
-
Probleme:
I dont know how to fix the error. -
What I Expect:
the texture of my “Sprite” should change to the one from the variablenew_drone_sprite
-
My Variables In global.gd:
var sprite_drone1 = preload('res://images/drones/drone_01_16p.png')
[…]
var sprite_drone2 = preload('res://images/drones/drone_02_16p.png')
-
Function In drone.gd From drone.tscn:
var my_string = 'global.sprite_drone'
print(my_string) → global.sprite_drone
var rand_nbr = 2
# will later be replaced by randi()%11+1
print(rand_nbr) → 2
var new_string = str(my_string, rand_nbr)
print(new_string) → global.sprite_drone2
var new_drone_sprite = str2var(new_string)
print(drone_sprite) → Debuger: Error calling built-in function ‘str2var’: Parse error at line 0: Unexpected identifier: ‘global’.
get_node("Sprite").texture = new_drone_sprite
- Additionnal Info:
get_node("Sprite").texture = global.sprite_drone2
# this work as intended
Godot v3.0.beta.build1 | W7.64 # probably both unrelated to the error
How can i make the function str2var work as i want ? or is there anothere way to achieve what i want ?