I can't seem to get my animations to finish and sounds to play before changing scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

Hi all,

I have a condition, that when it reaches 7 it kicks in, as shown below:

elif failedAttempt == 7 and not progression:
	playSound("neckSnap")
	get_node("man/head/torso/hips/leg_l").show()
	get_node("man/AnimationPlayer").play("fall")
	globals.hung = true				#we is dead.  So we can process death stuff in messages to player

	#play a timer so that we can hear the sounds, watch the animation, etc.  THEN move to next scene
	timer.set_one_shot(true)
	timer.set_wait_time(0.6)
	timer.connect("timeout", self, "_on_Timer_timeout")
	timer.start()
	print("timer did that thing")
	_on_Timer_timeout()	#go to finish screen

The function _on_Timer_timeout() loads up the next scene, which stops anything in this scene. What I’m trying to do, as you can see, is play the sound neckSnap and an animation called fall before heading off to the next scene.

I don’t know what’s wrong with my timer, primarily because I’m not very good at all of this as yet. Can anyone see anything glaringly obvious as to why it’s jumping straight to the next scene via _on_Timer_timeout() rather than playing the sound and animation?

Thanks a tonne… Rob

:bust_in_silhouette: Reply From: jospic

Probably, your sound and animation durations are longer than timer waiting time.
I suggest to use a Call function track keyframe at the end of animation that calls changing scene.

-j

Thank you that does sound like a great idea.

I just had a go though and when I create a new function track, a dialog appears and asks me “Call functions in which node?”

The problem is it’s only showing me nodes in the current scene but I want to call a function in another scene. Is there a way to do that?

EDIT: I ended up just moving the function to the local scene but if you do know it would be interesting as I’m sure this will come up. Thanks again for the help.

Robster | 2016-10-19 04:37

If your function is critical you can declare it in a singleton script (for example globals.gd) and then call it from any other scene with:

get_node("/root/globals").yourFunctionName()

Regards
-j

jospic | 2016-10-19 07:46

Finally figured out the singleton concept. Really useful thank you.

Robster | 2016-10-23 02:04