This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
–1 vote

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.

in Engine by (519 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!

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

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!

by (519 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.