![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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:
tool
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():
queue_free()
player.collect_loot(type)
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.
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