GODOT-4.2
Hi have a question, im trying to use XML to load sprite from my game from scraps
this is the code
pawn.gd
func _load_stats_from_xml():
pawn_stats = Utils.load_pawn_stats_from_xml("res://stats/pawn_stats.xml")
if pawn_stats.has(pawn_class):
var stats = pawn_stats[pawn_class]
move_radious = stats["move_radious"]
jump_height = stats["jump_height"]
attack_radious = stats["attack_radious"]
attack_power = stats["attack_power"]
max_health = stats["health"]
curr_health = max_health
# Leer la ruta de la sprite desde el XML
if "sprite" in stats:
var sprite_path = str(stats["sprite"])
print("Sprite path:", sprite_path)
$Character.texture = load(sprite_path)
else:
print("Error: No se encontraron estadísticas para la clase de peón:", pawn_class)
and XML files is
<pawn class="0">
<sprite>assets/sprites/characters/chr_pawn_knight.png</sprite>
<move_radious>3</move_radious>
<jump_height>0.5</jump_height>
<attack_radious>1</attack_radious>
<attack_power>20</attack_power>
<health>50</health>
</pawn>
idk why my sprite arent loading correctly.
and debugger error is:
print from script
Stats de peones cargados:{ 0: { "sprite": 0, "move_radious": 3, "jump_height": 0.5, "attack_radious": 1, "attack_power": 20, "health": 50 }, 1: { "sprite": 0, "move_radious": 5, "jump_height": 3, "attack_radious": 6, "attack_power": 10, "health": 35 }, 2: { "sprite": 0, "move_radious": 5, "jump_height": 3, "attack_radious": 6, "attack_power": 10, "health": 35 }, 3: { "sprite": 0, "move_radious": 5, "jump_height": 3, "attack_radious": 6, "attack_power": 10, "health": 35 }, 4: { "sprite": 0, "move_radious": 5, "jump_height": 3, "attack_radious": 6, "attack_power": 10, "health": 35 }, 5: { "sprite": 0, "move_radious": 5, "jump_height": 3, "attack_radious": 6, "attack_power": 10, "health": 35 }, 6: { "sprite": 0, "move_radious": 5, "jump_height": 3, "attack_radious": 6, "attack_power": 10, "health": 35 } }
Sprite path:0
E 0:00:02:0306 pawn.gd:58 @ _load_stats_from_xml(): Resource file not found: res://0 (expected type: )
<Error de C++> Condition "!file_check->file_exists(p_path)" is true. Returning: Ref<Resource>()
<C++ Source> core/io/resource_loader.cpp:279 @ _load()
<Stack Trace> pawn.gd:58 @ _load_stats_from_xml()
pawn.gd:160 @ _load_stats()
pawn.gd:179 @ _ready()
the png files have the correct path*
im trying to load sprite from a xml file, but idk if im doing it correctly, can you help me? thanks a lot, sry for my bad english