0 votes

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 = CircleShape2D.new()
        $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 = CircleShape2D.new()
        $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: https://youtu.be/VWOqgzgBNqY).

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

asked Feb 14, 2019 in Engine by fpicoral (503 points)

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.

Thanks for the help!

1 Answer

0 votes
Best answer

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!

answered Feb 15, 2019 by fpicoral (503 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.