Can't change exported var when using tool script

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

Hey there,
I’m using Godot3.1 Beta3. I have a “Loot” object that can be either a folder or a suitcase. I created a function to change the loot sprite on ready based on a exported variable and it works fine but I can only see the selected sprite when the game runs.
To “fix” that, I tried using the keyword tool at the top of the script, here is the code:

extends Area2D

var player

export(String, "Folder", "Suitcase") var type = "Folder" setget set_loot_type

func _ready():
	if not Engine.is_editor_hint():
		player = Global.player

#Sets the sprite and collision shape
func set_loot_type(type):
	if type == "Folder":
		$Sprite.texture = load("res://images/png/Loot/folder.png")
		$Sprite.scale = Vector2(0.3, 0.3)
		$Collision.shape =
		$Collision.shape.radius = 30
	if type == "Suitcase":
		$Sprite.texture = load("res://images/png/Loot/suitcase.png")
		$Sprite.scale = Vector2(0.3, 0.3)
		$Collision.shape =
		$Collision.shape.radius = 30
#Signal body entered
func collected(body):
	if not Engine.is_editor_hint():

After I added the tool keyword, even after restarting the editor, when I change the variable on the editor, it does not change (see it here:

If I delete the keyword tool, it works just fine.

You’ve got to actually assign the value to your exported variable “type” (inside your setter function). Godot currently queries the value and sees that it hasn’t been changed.

wombatstampede | 2019-02-14 19:23

Thanks for the help!

fpicoral | 2019-02-15 00:19

Fine question. I down-voted it to hurt its search rankings: your problem is specific to your code.

CharlesMerriam | 2020-10-27 22:18

:bust_in_silhouette: Reply From: fpicoral

I did not set the type variable to the new value on my setter function. I also had to make a small change on the code because the exported var was called type and the argument for the setter variable was also type.

Thanks @wombatstampede for the help!