"Every 5 seconds" conditon problem with layouts

Get help using Construct 2

Post » Sun Aug 30, 2015 7:51 pm

Hi,

I have a Main Title Screen Layout, and once clicked player goes to Layout 02.
At the beginning of Layout 02 I have a condition: "Every 5 seconds" - spawn a box.

Problem is, when I wait in the Main Title Screen Layout 5 seconds or more, and then click to go to Layout 02, the box is spawned already.
So it seems that the timer - the "Every 5 seconds" condition is counting when the player is still in the Main Title Screen Layout

How can this be? Am I doing it wrong? Is there another way to to make the "Every 5 seconds" condition work only after entering a layout?

Thanks for the help.

Edit: I tried to look for a condition: "On entering layout", but in the end couldn't find it.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sun Aug 30, 2015 8:13 pm

@Solomon

do the layouts share the same event sheet?

there is an event "On Start of Layout"

I had a similar issue that I thought might be some kind of bug, but turned out it was an error in my code. So, I would think there is something you are doing that is causing this - and it is impossible to say what it is without seeing your code.
B
98
S
35
G
20
Posts: 438
Reputation: 17,875

Post » Sun Aug 30, 2015 8:26 pm

"Every X seconds" don't work as "per layout". It counts using the game time from the start.
ImageImageImageImage
B
158
S
66
G
43
Posts: 2,603
Reputation: 35,868

Post » Sun Aug 30, 2015 8:27 pm

AllanR wrote:@Solomon

do the layouts share the same event sheet?

there is an event "On Start of Layout"

I had a similar issue that I thought might be some kind of bug, but turned out it was an error in my code. So, I would think there is something you are doing that is causing this - and it is impossible to say what it is without seeing your code.


Hmm interesting... didn't know that layouts can share 1 event sheet. I am going to do some reading on this now.

Sorry what I mean I cant find an "If Start of Layout" event or how to implement it as such.

Thanks for the tips will do some more reading and if I dont manage to solve my problem will post a snippit of my code.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sun Aug 30, 2015 8:28 pm

shinkan wrote:"Every X seconds" don't work as "per layout". It counts using the game time from the start.



Oh wow... Really? Thats a bummer... any other simple condition to wait until a layout is loaded? Could you please share any other tips on how I can solve this matter?

Thanks!
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sun Aug 30, 2015 8:36 pm

There is no straight answer to that. It all depends what you want to achieve.

You could use a Timer behavior, Groups, check if 5 seconds have passed for current layout etc.
ImageImageImageImage
B
158
S
66
G
43
Posts: 2,603
Reputation: 35,868

Post » Sun Aug 30, 2015 8:43 pm

@shinkan

I see... interesting.
Basically, I want a box to spawn every 5 seconds after a layout is loaded.
I have a title screen on 1 layout, during which I don't want anything to happen. I have it set that by clicking on it the player goes to another layout, which upon entering, after every 5 seconds a box is spawned.

Edit: Only thing I cant set up is the part where the spawn timer starts only once the player enters the second layout.

So basically:

_____If Layout B is loaded
________Every 5 seconds spawn box
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Sun Aug 30, 2015 9:54 pm

@Solomon - another way is to use a global variable:

On Start of Layout B --> set NextSpawnTime = Time + 5

then, instead of every 5 seconds:

System Compare two values ( Time >= NextSpawnTime ) --> spawn box, and set NextSpawnTime = Time + 5

The only thing to watch out for is if you pause the game (or open a settings menu, or display a message) - you would have to save the remaining wait time:
TimeToSpawn = NextSpawnTime - Time

then when you unpause, set NextSpawnTime = Time + TimeToSpawn
B
98
S
35
G
20
Posts: 438
Reputation: 17,875

Post » Sun Aug 30, 2015 10:21 pm

AllanR wrote:@Solomon - another way is to use a global variable:

On Start of Layout B --> set NextSpawnTime = Time + 5

then, instead of every 5 seconds:

System Compare two values ( Time >= NextSpawnTime ) --> spawn box, and set NextSpawnTime = Time + 5

The only thing to watch out for is if you pause the game (or open a settings menu, or display a message) - you would have to save the remaining wait time:
TimeToSpawn = NextSpawnTime - Time

then when you unpause, set NextSpawnTime = Time + TimeToSpawn



OH WOW! Thanks a lot for your time! Now I have to wrap my head around it :P

How much simpler would it be to have the ability just to toggle the "Every 5 seconds" condition to either start counting at beginning of game, or start counting at beginning of each layout?

Construct 2 is great don't get me wrong, but it is seemingly simple things like this that just put me off for a bit once in a blue moon.

Anyhow once I get this working by your example I'm sure this logic structure will come in handy in some other part of my game.

Once again thanks for your time :)
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests