Restart a layout when player dies

For questions about using Classic.

Post » Mon May 30, 2011 6:28 am

The wiki says that if you do a transition to the current layout you get a restart. I have a global variable called curlevel that starts at 0 and goes up 1 every time the player hits a checkpoint that teleports them to the next level. When the player dies by hitting a wall or enemy they play an animation and when that is finished I wait and then go to layout global(curlevel). The problem I'm having is that when the player hits a wall in the last level it crashes.

Is there an easier way to implement this? Is there a way to specify current level rather than a number in the transition function.

.cap is here:

http://dl.dropbox.com/u/22863144/sailboatgame.cap
B
1
G
1
Posts: 9
Reputation: 443

Post » Mon May 30, 2011 2:21 pm

Can't look into your cap, it sounds like something may go wrong with the counter.

However, there is no easier way then using 'go to layout'. You are not forced to use numbers, though. If you name your layouts, you can use the names as strings as well. If a layout is called 'uberlevel' then you'd call it with
go to layout "uberlevel"
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon May 30, 2011 2:45 pm

Try 'Debug all' and watch the value of 'curlevel' to see if it is what you expect. I find debug invaluable for seeing what value is actually being set, compared to what you expect it to be.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,849
Reputation: 48,299

Post » Mon May 30, 2011 3:03 pm

I checked and the currentlvl value starts at 0 then is set to 2 after the first level, then 4 on the second level, maybe thats the reason
B
6
S
2
G
1
Posts: 122
Reputation: 1,194

Post » Mon May 30, 2011 5:03 pm

Yes, that will be it.
The first layout has the number 1, if you would have a total of 3 layouts, then number 3 is the highest number you can go to.
The problem of counting 2x per level could be that the condition for counting up ist still true when entering the new level. Unfortunately, my pc is broken-down, and this 11-year old antique computer I have to use until my pc is repaired refuses to install Construct, so I can't look into the cap.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon May 30, 2011 5:48 pm

Instead of using a global to keep track of what the current level, you could just use the system expression "LayoutNumber" to get the current level.
B
79
S
24
G
54
Posts: 4,750
Reputation: 40,763

Post » Tue May 31, 2011 2:30 am

Thanks ROJOhound, that's fixed it. :)
B
1
G
1
Posts: 9
Reputation: 443


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests