Timer Issue with Change_Scene_to_Packed

Godot Version

4.3

Question

`Hi, so I am doing something very basic… Something that doesn’t really have to be done…
I have already paid for a Google Play Company so I figured instead of just (Config Splash Screen) I would make a piece of code that runs the Company branding for 5 seconds → then change_scene_to_packed() → then run the Game Logo for 5 Seconds and then after change_to_packed() run the title screen…

In the past I have used the inspector nodes for coding but this time I used AI to get started (Which means instead of clicking the nodes I was using Code…

I am now using a Timer Node, the Timer is linked to this script:

extends Timer

@onready var timer: Timer = $Timer
#PRELOADS

var company_splash = preload(“res://Scenes/LoadingScreens/CompanySplash.tscn”)
var branding_splash = preload(“res://Scenes/LoadingScreens/BrandingScreen.tscn”)
var title_screen = preload(“res://Scenes/TitleScreen.tscn”)

var step:= 0;

func _ready() → void:
step = 1;
timer.start(5.0)
timer.timeout.connect(_on_timer_timeout)
pass

func _on_timer_timeout() → void:
match step:
1:
get_tree().change_scene_to_packed(company_splash)
timer.start(5.0)
step = 2
2:
get_tree().change_scene_to_packed(branding_splash)
timer.start(5.0)
step = 3
3:
get_tree().change_scene_to_packed(title_screen)

The error I am currently getting is: cannot call method start in null value

Which I know is because it doesn’t know timer.start is calling on the Timer Node but I don’t know how to fix it.

(Noobie question for a gamemaker Lol)`

Please put ``` on the lines above and below your code like this:

```gdscript
#Code here
```

So it appears like this:

#Code here

It’s difficult to read with all the tabs removed.

If this is the timer’s script, you probably don’t want to reference another timer like that:

@onready var timer: Timer = $Timer
timer.start(5.0)
timer.timeout.connect(_on_timer_timeout)

and instead just call the functions directly:

start(5.0)
timeout.connect(_on_timer_timeout)

Thank you two for your help, especially your help @hyvernox
I did not get any errors in this and it partially works…
I had to wait awhile but it eventually shows the Company Logo before crashing… I think I might know why…

First I’ll show the code:

	match step:
		1:
			get_tree().change_scene_to_packed(company_splash)
			start(5.0) #This is where the error is
			step = 2
		2:
			get_tree().change_scene_to_packed(branding_splash)
			start(5.0)
			step = 3
		3:
			get_tree().change_scene_to_packed(title_screen)

Now, the Timer Node has a wait time which I set to 5 seconds, but in the code:

start(5.0)

I think the error is start is being assigned to 5.0 seconds each time… and in the inspector it is waiting 5 seconds (1 time?)

Would this be possible/fix it?

	match step:
		1:
			get_tree().change_scene_to_packed(company_splash)
			start() #Runs for 5 seconds naturally?
			step = 2
		2:
			get_tree().change_scene_to_packed(branding_splash)
			start() #Runs for 5 seconds naturally?
			step = 3
		3:
			get_tree().change_scene_to_packed(title_screen)
			

start(5.0) just sets wait_time to 5.0 and starts the timer, so I don’t think this would help.
I assume it’s the use of get_tree().change_scene_to_packed(): This function replaces the current scene by the packed scene, which should delete the timer (or at least remove it from the scene tree). I think it would work if the timer’s scene would be used as a singelton though?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.