Godot Version
4.6
Question
i am working on a simple fnf style rhythm game and when playing on godot the error doesnt appear but when i play on browser this error appears:
E 0:00:14:865 _process: Invalid access to property or key ‘has_passed’ on a base object of type ‘previously freed’. key_listener.gd:37 @ _process() key_listener.gd:37 @ _process()
Also whenever i play on browser the arrows fall slower, they are more clumped up and they disappear before its supposed to so it doesn’t even reach where your supposed to hit it. I will include the code of the scripts that are used for the game and also what how the game looks compared to the browser. Please include the code you would insert to fix because i am still new and learning Please help and thank you
#Error: E 0:00:14:865 _process: Invalid access to property or key 'has_passed' on a base object of type 'previously freed'. <GDScript Source> key_listener.gd:37 @ _process() <Stack Trace> key_listener.gd:37 @ _process()
#falling key.gd:
extends Sprite2D
@export var fall_speed: float = 2.0
var init_y_pos: float = -360
# true if falling key has passed the allowed input frame
var has_passed: bool = false
var pass_threshold = 300
func _init():
set_process(false)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
global_position += Vector2(0, fall_speed)
# Find out how long it takes for arrow to reach critical spot
if global_position.y > pass_threshold and not $Timer.is_stopped():
#print($Timer.wait_time - $Timer.time_left)
$Timer.stop()
has_passed = true
func Setup(target_x: float, target_frame: int):
global_position = Vector2(target_x, init_y_pos)
frame = target_frame
set_process(true)
func _on_destroy_timer_timeout():
queue_free()
#Key_Listener.gd:
extends Sprite2D
@onready var falling_key = preload("res://macondo-game/Scenes/Level Scenes/Level 3 Scenes/falling_key.tscn")
@onready var score_text = preload("res://macondo-game/Scenes/Level Scenes/Level 3 Scenes/score_press_text.tscn")
@export var key_name: String = ""
var falling_key_queue = []
# If distance_from_pass is less than threshold, give that score
var perfect_press_threshold: float = 30
var great_press_threshold: float = 50
var good_press_threshold: float = 60
var ok_press_threshold: float = 80
# otherwise, miss
var perfect_press_score: float = 250
var great_press_score: float = 100
var good_press_score: float = 50
var ok_press_score: float = 20
func _ready():
Level3Signals.CreateFallingKey.connect(CreateFallingKey)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if Input.is_action_just_pressed(key_name):
Level3Signals.KeyListenerPress.emit(key_name, frame)
# Make sure there is a falling key to check for this given key
if falling_key_queue.size() > 0:
# If that falling key has passed, remove it from the queue
if falling_key_queue.front().has_passed:
falling_key_queue.pop_front()
# PRINT MISS
var st_inst = score_text.instantiate()
get_tree().get_root().call_deferred("add_child", st_inst)
st_inst.SetTextInfo("MISS")
st_inst.global_position = global_position + Vector2(0, -20)
Level3Signals.ResetCombo.emit()
# If key is pressed, pop from the queue and calculate distance from critical point
if Input.is_action_just_pressed(key_name):
var key_to_pop = falling_key_queue.pop_front()
if is_instance_valid(key_to_pop):
var distance_from_pass = abs(key_to_pop.pass_threshold - key_to_pop.global_position.y)
var press_score_text: String = ""
if distance_from_pass < perfect_press_threshold:
Level3Signals.IncrementScore.emit(perfect_press_score)
press_score_text = "PERFECT"
Level3Signals.IncrementCombo.emit()
elif distance_from_pass < great_press_threshold:
Level3Signals.IncrementScore.emit(great_press_score)
press_score_text = "GREAT"
Level3Signals.IncrementCombo.emit()
elif distance_from_pass < good_press_threshold:
Level3Signals.IncrementScore.emit(good_press_score)
press_score_text = "GOOD"
Level3Signals.IncrementCombo.emit()
elif distance_from_pass < ok_press_threshold:
Level3Signals.IncrementScore.emit(ok_press_score)
press_score_text = "OK"
Level3Signals.IncrementCombo.emit()
else:
press_score_text = "MISS"
Level3Signals.ResetCombo.emit()
key_to_pop.queue_free()
var st_inst = score_text.instantiate()
get_tree().get_root().call_deferred("add_child", st_inst)
st_inst.SetTextInfo(press_score_text)
st_inst.global_position = global_position + Vector2(0, -20)
func CreateFallingKey(button_name: String):
if button_name == key_name:
var fk_inst = falling_key.instantiate()
get_tree().get_root().call_deferred("add_child", fk_inst)
fk_inst.Setup(position.x, frame + 4)
falling_key_queue.push_back(fk_inst)
func _on_random_spawn_timer_timeout():
#CreateFallingKey()
$RandomSpawnTimer.wait_time = randf_range(0.4, 3)
$RandomSpawnTimer.start()

