Loop counter next scene

I have a loop counter on the main timeline and want to go to the next scene after 3 loops. Can someone help with this JaveScript code, please?

Hei Steveo,
you can do this either by scripting or without scripting. Look at the attached files. The none script version works as follows:

Main Timeline loops, at the end of the loop it causes the timeline 'counter' to continue. Counter will stop for the first two times and change the innerHTML of the counter. At the end of the third loop 'counter' starts the timeline action 'goto next Scene'.

btw. - for the coders among you: I tried to initialize the counter variable this way:

	// initialize counter variable
	if (typeof counter == 'undefined') {

		counter = 0;
	}

If I declare the variable as 'var counter = 0;' the variable doesn´t count up. Can anyone tell me why?

Thanks in advance.

loopChangeSceneNoScript.zip (25.1 KB)
loopChangeSceneScript.zip (24.3 KB)

2 Likes

Hi Kalle. Thanks for the response. The script is not working for me. I've attached the hype file. Can you take a look? Many thanks!
banner.hype.zip (124.2 KB)

Hei Steveo,

  • In checkCounter() you have to delete those parts which deal with filling the textfield (this was only for illustration...)

  • You don´t need the timeout for the scene transition, because you´re setting the delay on the Main Timeline

  • I´m not sure why you are working with a listener on your click-button (in both scenes)? Anyway - the definition inside the innerHTML will not work the way you´re trying to do it, besides - you are trying to adress an incorrect ID (which would be 'bg-exit' and not 'bg-exit-1'). To make a long story short: In my eyes - forget about the listener (even in the bgExitHandler() function, since it calls the function itself... :thinking:), just use an 'on mouse down' hype button event. (Unless the listener stuff is doing some google voodo, I´m not familiar with... e.g. what is 'EnablerListener()' doing? It doesn´t run at all... :thinking:)

Hope, this helps, regards Kalle

banner_working.zip (113.3 KB)

2 Likes

To me it looks like you are redeclaring counter by using it also with a var declaration but across two scopes which is causing a clash.

counter & var counter are two different objects using the same name.

There is no need to do this and you would normally just not do it.

I also normally avoid using variables that do not have a clear scope. I will normally add window. to create a global var and that's me being lazy about scoping and pollution of scope.

Ideally in this scenario you would just keep things in house within hypes scope and instead of counter

replace it with hypeDocument.customData.counter

2 Likes

Hi Mark, thanks for that. Think, I´ve got it. I know, I should get used to write variables to customData - fighting old habits... :grinning:

3 Likes