Create a custom Event

Get help using Construct 2

Post » Sat Aug 18, 2012 3:10 pm

If several different things can trigger a single action (e.g. several ways a game can end- run out of life, run out of time, complete it), i would like to create my own event called say "gameEnd". Then If the time runs out, I just have to "raise" the gameEnd event etc.

This way I only have to write the gameEnd event and actions once, and can raise it in lots of places.

I have searched on "custom event" but cant find anything. There is nothing under events in the manual. Any ideas?

If this is missing, its a pretty big omision. I guess the work around would be to duplicate a lot of code, or possibly to try and construct a big complex condition statement to try and catch all the places where they action is required.

Or perhaps you can simulate this by creating a hidden sprite, then set it to say invisible in several places to simulate "raising" the event, then have your "handler" condition on the visibility attribute?
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Aug 18, 2012 3:15 pm

You can put that code into separate event sheet and then use "include event sheets" to insert it do different event sheets, groups, sub-events...
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Aug 18, 2012 3:15 pm

I guess another way is to create a polling effect, e.g. set a global variable called "gameEnd" to 1 to "raise" the event, then every tick compare the variable to 1, and if it reaches 1, do some action and set it to 0. The problem is that events could be lost because Im guessing there is no mutual exclusion on the variable.
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Aug 18, 2012 3:31 pm

Hi Shinkan, I dont see how having mutliple event sheets can simulate raising a custom event in several places a single game? My understanding from the manual: http://www.scirra.com/manual/121/event-sheets
is that they are just like include files if you want to include your events in multyple games (I only have one game).
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Aug 18, 2012 3:35 pm

It sounds to me like what you want to do can be done with the function plugin. Link.
B
73
S
20
G
10
Posts: 524
Reputation: 9,896

Post » Sat Aug 18, 2012 3:56 pm

If I correctly understand your first post

inc_ev.capx

you can click on button or the sprite and every time when current "action" associated whit that object finish (click on button, sprite fade finish) it will trigger the same events for "game over".

not a best example, but you'll get the point.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Aug 18, 2012 4:17 pm

Wow, thats a very useful feature - the manual should include this in the sheets page!

I had no idea you could create a sheet, with actions with no event conditions, then call it as an action!

+100 credits for Shinkan.
B
15
S
5
G
2
Posts: 357
Reputation: 3,691


Return to How do I....?

Who is online

Users browsing this forum: Virpoja, Yahoo [Bot] and 19 guests