Godot Version
4.6.3.stable
Question
Trying to add a cooldown to changing the gravity. Whenever change_gravity() is run it causes the error; Cannot call method ‘start’ on a null value. I know that g_cooldown_timer’s value is ‘null’ but I’m not exactly sure what that means aside from that it has no value.
I have checked other similar questions, but while they may have had the solution to my problem I --quite honestly-- was not able to apply them to my own code.
I have given the Scene Tree and the Script for Gravity Manager below. I apologize in advance if I did not give enough information, please ask if I need to give any more details.
gravity_manager.gd
extends Node
class_name Gravity_Manager
@onready var g_cooldown_timer: Timer = $"../G Cooldown Timer"
const GRAVITY = 3000.0
var g_dir : Vector2
var g_on := 1
var cooling_down := false
func _physics_process(delta: float) -> void:
if Input.get_vector("g_left","g_right","g_up","g_down") and not cooling_down:
change_gravity(Input.get_vector("g_left","g_right","g_up","g_down"))
if Input.is_action_just_pressed("g_toggle"):
toggle_gravity()
func change_gravity(dir : Vector2):
g_dir = dir
g_on = 1
cooling_down = true
g_cooldown_timer.start(-1)
func toggle_gravity():
if g_on == 1:
g_on = 0
print(g_on)
elif g_on == 0:
g_on = 1
print(g_on)
Scene Tree
Thank you to anyone who replies.
