Godot Version
4.6
Question
So i am making a rhythm game and after like 20 seconds of playing the game it stops and i get this: E 0:00:43:135 _process: Invalid access to property or key ‘pass_threshold’ on a base object of type ‘Nil’.
I dont know what to do about it. i will include the code to help. Tell me if you need photos of the project because i will send it if needed. Please help and thank you
If you share code, please wrap it inside three backticks or replace the code in the next block:
#Error:
_process: Invalid access to property or key ‘pass_threshold’ on a base object of type ‘Nil’.
#Falling key.gd
extends Sprite2D
@export var fall_speed: float = 2.5
var init_y_pos: float = -360
var has_passed:bool = false
var pass_threshold = 300.0
func _init():
set_process(false)
func _process(_delta):
global_position += Vector2(0, fall_speed)
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()
#KeyListener.gd
extends Sprite2D
@onready var falling_key = preload("res://Scenes/Level Scenes/Level 3 Scenes/falling_key.tscn")
@onready var score_text = preload("res://Scenes/Level Scenes/Level 3 Scenes/score_press_text.tscn")
@export var key_name: String = ""
var falling_key_queue = []
var perfect_press_threshold: float = 30
var great_press_threshold: float = 50
var good_press_threshold: float = 60
var ok_press_threshold: float = 80
var perfect_press_score = 250
var great_press_score = 100
var good_press_score = 50
var ok_press_score = 20
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if falling_key_queue.size() > 0:
if falling_key_queue.front().has_passed:
falling_key_queue.pop_front()
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 Input.is_action_just_pressed(key_name):
var key_to_pop = falling_key_queue.pop_front()
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():
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_spawm_timer_timeout():
CreateFallingKey()
$RandomSpawmTimer.wait_time = randf_range(0.4, 3)
$RandomSpawmTimer.start()