"Every X Seconds" not working in a function

Get help using Construct 2

Post » Thu Jul 11, 2013 5:22 pm

Hi all,

I have a game that has multiple levels. Each level has its own timer that controls when the level ends. Because of this, I have externalized the level config into a function that is called at various points in the game. (called initially when the game loads, called when someone restarts a level etc.)

Unfortunately, it seems that my "Every X Seconds" loop isn't working within the function.

See the link below for a very basic capx demonstrating this.
https://www.dropbox.com/s/e0b762pbkup6bl3/TestingLoopsInFunctions.capx

What Should Happen: The text on the main screen should count down from "3".

What is Happening: The text is sitting on "3".

Any thoughts on this? I have a feeling I'm missing something very obvious, as I would imagine this would just work.
B
5
S
1
G
1
Posts: 18
Reputation: 566

Post » Thu Jul 11, 2013 5:28 pm

That can't work. You call a function once, then it returns, so the Every X seconds code won't be called again. Just move the code out of the function. It will only be called if LevelNum=2 anyway.
ImageImageImage
B
71
S
21
G
203
Posts: 3,584
Reputation: 115,072

Post » Thu Jul 11, 2013 6:42 pm

Hm ok good to know. I had a feeling that was the case.

So then I guess I have more of a "how would you do this" sort of question?

I have a timer that counts down from 60 for level 1. The level ends, and a screen comes up to tally your points. Then you hit continue, and level 2 begins (same background). I want to repeat all of the previous actions from Level 1, but with a different timer, and different (stronger) enemies...

Is there a simple way to achieve this? I was originally trying to put the loops into a function so I could say "ok begin level 2 actions."
B
5
S
1
G
1
Posts: 18
Reputation: 566

Post » Thu Jul 11, 2013 6:54 pm

One suggestion: Have a Global for your level. 'On start of layout' setup whatever else needs to be configured, creating sprites, setting values, timers, etc, based on the level number. You can use a function for this (or not). At the end of the current timer, add one to the level counter, and 'Restart layout'.
ImageImageImage
B
71
S
21
G
203
Posts: 3,584
Reputation: 115,072

Post » Thu Jul 11, 2013 7:10 pm

Yep, I messed with it some more, and landed on that. Rather than having a function for each level, I just have a large check for LevelNum, and then each config item is within that conditional statement. Thanks for the help!
B
5
S
1
G
1
Posts: 18
Reputation: 566

Post » Thu Jul 11, 2013 8:46 pm

You can always loop function until it meets certain condition. For example

-On Function "AAA"
--If A=\=B ( or any other condition )
---do something
---- Call Function "AAA"
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
78
S
21
G
19
Posts: 1,932
Reputation: 17,316

Post » Thu Jul 11, 2013 9:16 pm

Ah good point. I'll keep that in mind- thanks.
B
5
S
1
G
1
Posts: 18
Reputation: 566


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 2 guests