Topic was automatically imported from the old Question2Answer platform.
Asked By
Sunil B
Used common script for different duplicated coins with modified scene name & sprite, need to assign different score values for each coin, how to script it
This is my script:
extends Area2D
onready var animatesprite = $AnimationPlayer
var score
#want it this way: #if spirt or scene == “citrine”:
extends Area2D
onready var animatesprite = $AnimationPlayer
var score = 0
func _ready():
if "Citrine" in name:
score = 5
elif "Diamond" in name:
score = 10
elif "Ruby" in name:
score = 6
func onbodyentered(body: Node) -> void:
queue_free()
Know that when comparing a string this way that it is case sensitive and must exactly match
Thanks it works
Sunil B | 2021-09-07 13:06
That may be related to the queue_free() if the engine still uses that node when its being freed.
Use call_deferred(“queue_free”) this is just an assumption and may be something else entirely so you can set break points to find the root of that problem
Wakatta | 2021-09-07 13:42
#Was using this which caused the game crash:
func _on_body_entered(body: Node) → void:
PlayerData.score += _ready()
queue_free()
#Solved when changed to this:
func _on_body_entered(body: Node) → void:
PlayerData.score += score
queue_free()