Why does this script doesn't works when exported?

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

Basicly, this code changes the texture of the character based on the button name, and it works fine when using the engine, but when exported, the sprite just reloads.

extends Button
var actualTexture = ""
var actualItem = 1
var file = File.new()

func _ready():
	actualTexture = get_owner().get_node("Player/Sprites/"+self.name).get("texture").get_path()

func _input(event):
	if pressed:
		actualItem += 1
		if actualItem < 10:
			if file.file_exists(actualTexture.replace(actualTexture[-6], actualItem)):
				get_owner().get_node("Player/Sprites/"+self.name).set_modulate(get_parent().get_node("ColorPicker").color)
				get_owner().get_node("Player/Sprites/"+self.name).set_texture(load(actualTexture.replace(actualTexture[-6], actualItem)))
			else:
				actualItem = 1
				get_owner().get_node("Player/Sprites/"+self.name).set_texture(load(actualTexture.replace(actualTexture[-6], actualItem)))
		elif actualItem < 100:
			if file.file_exists(actualTexture.replace(actualTexture[-7][-6], actualItem)):
				get_owner().get_node("Player/Sprites/"+self.name).set_texture(load(actualTexture.replace(actualTexture[-7][-6], actualItem)))
			else:
				actualItem = 1
				get_owner().get_node("Player/Sprites/"+self.name).set_texture(load(actualTexture.replace(actualTexture[-7][-6], actualItem)))
		else:
			if file.file_exists(actualTexture.replace(actualTexture[-8][-7][-6], actualItem)):
				get_owner().get_node("Player/Sprites/"+self.name).set_texture(load(actualTexture.replace(actualTexture[-8][-7][-6], actualItem)))
			else:
				actualItem = 1
				get_owner().get_node("Player/Sprites/"+self.name).set_texture(load(actualTexture.replace(actualTexture[-8][-7][-6], actualItem)))

Are you sure the paths to the textures are the same? I see you are using absolute paths which may change after you have exported the game. Maybe try to figure out a way to use relative paths. Check these out too:

Data paths — Godot Engine (3.0) documentation in English

https://forum.godotengine.org/40151/troubleshooting-projectsettings-globalize_path-godot-6

johnygames | 2019-12-22 19:39