Hiya,

I'm trying to add 5 minutes to my in-game clock every time a Timer runs out, but I can't seem to make the timer do anything. Every time I run the scene it breaks and says 'Attempt to call function 'start' in base 'null instance' on a null instance.'

I've tried adding separately
onready var timer = get_node("Timer")
and
onready var timer = $Timer
but neither changed the outcome.

If I call print_tree_pretty() it only shows Calendar, not the Timer child node.
'timer' and 'Timer' are most definitely spelled correctly everywhere, Timer is also definitely a child of the node I'm writing the script in. What am I missing here?

  • nikoyishi Does my Calendar script being an autoload have anything to do with it?

    Probably, yes. Look at the remote tab when then game is running so you can see the tree.

Probably something off with your node tree. Or the Timer is not named "Timer", it can have any name.

    Another possibility is that you're calling 'start' too early, before the Timer node is ready.

      cybereality Probably something off with your node tree. Or the Timer is not named "Timer", it can have any name.

      My node tree is just a Node called Calendar, directly below it is a child Timer called Timer. So I don't think that's the case here.

      DaveTheCoder Another possibility is that you're calling 'start' too early, before the Timer node is ready.

      I'm setting the wait time and starting the timer in a _ready function, is that too early?
      Here's my code in case I'm missing something:

      func _ready():
      	print_tree_pretty()
      	timer.set_wait_time(real_seconds_for_one_game_minute)
      	timer.start()

      I don't think the code below this has anything to do with my issue, but just in case:

      func _on_Timer_timeout():
      	current_minute += 05
      	if current_minute >= 60:
      		current_minute = 00
      		current_hour += 1
      		if current_hour >= 24:
      			current_hour = 5
      			day += 1
      			day_name_ref += 1
      			if day_name_ref >= 6:
      				day_name_ref = 0
      			current_day = day_names[day_name_ref]
      			emit_signal("day_changed")
      			if day > 27:
      				day = 0
      				month += 1
      				if month > 12:
      					month = 0
      					year += 1
      					emit_signal("year_changed")
      				current_month = month_names[month]
      				emit_signal("month_changed")
      	timer.start()

      Does my Calendar script being an autoload have anything to do with it?

        nikoyishi Does my Calendar script being an autoload have anything to do with it?

        Probably, yes. Look at the remote tab when then game is running so you can see the tree.