Why does my code throw the error "E 0:00:04:0444 Area2D.gd:21 @ _on_coin_bottom_body_entered(): Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead."? Everything works perfectly, and i've tried adding call_deferred("") to everywhere i can think of but i just broke more lmao. Anyone know what it means?
Coin Block code:
extends StaticBody2D
var Coinscene = preload("res://Scenes/Tiles/coin.tscn").instantiate()
var empty = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_coin_bottom_body_entered(body):
if body.get_name() == "Player" and not empty:
empty = true
$AnimationPlayer.play("Bump")
add_child(Coinscene)
Coinscene.coin_collect()
await $AnimationPlayer.animation_finished
$AnimatedSprite2D.play("Bumped")
func _on_coin_top_body_entered(body):
if body.get_name() == "Player" and not empty:
if body.state == 2:
empty = true
$AnimationPlayer.play("BumpLower")
await $AnimationPlayer.animation_finished
$AnimatedSprite2D.play("Bumped")
Coin code:
extends Area2D
var collected = false
# Called when the node enters the scene tree for the first time.
func _ready():
$AnimatedSprite2D.play("Idle")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_body_entered(body):
if body.get_name() == "Player" and collected == false:
coin_collect()
func coin_collect():
collected = true
$AnimatedSprite2D.play("Spin")
$AnimationPlayer.play("Collect")
$CoinSound.play()
Coins.coins = Coins.coins + 1
await $CoinSound.finished
queue_free()