0 votes

I'm attempting to implement a legal crawl that displays before the game start, and then eventually transition to a StartMenu. I figured this could be done with a Timer object, through a script on the actual LegalCrawl.tscn Panel node. After 7 seconds, transition to the StartMenu.tscn.

Except, that in its current implementation, I am getting an error of Attempt to call function 'set_wait_time' in base 'null instance' on a null instance when it attempts to make the set_wait_time call (i've highlighted the offending LOC with a comment below). My initial presumption is that the Engine isn't loading the Timer class. This seems like the Class instance for Timer isn't being loaded. I'm still new to Godot, am I missing something here?

# TransitionToMenu.gd
# Transitions to the Menu Screen Scene

extends Panel

var timer

func _ready():
    """
    Inherits behavior from Ready Event
    """
    timer = get_node("Timer")
    timer.set_wait_time(5) # Errors Here: Attempt to call function 'set_wait_time' in base 'null instance' on a null instance.
    timer.connect("timeout", self, "_on_timeout_expire")
    timer.start()

func _on_timeout_expire():
    """
    This method runs the Scene loading method, tranisitioning to the main
    menu Scene.
    """
    get_tree().change_scene("res://StartMenu.tscn")
in Engine by (63 points)
edited by

Is "Timer" a Timer child of the node "LegalCrawl" ? If you try to add a timer from code, you are missing some steps"

var timer= Timer.new()
add_child(timer)
timer.connect("timeout",self,'_your_function',[variable])
timer.set_wait_time(5)
timer.start()

1 Answer

0 votes
Best answer

Most likely the offending line is this one:

timer = get_node("Timer")

My bet would be your path is wrong. You'll want to make sure there is actually a Timer node as a child of this node with the script.

by (5,264 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.