On Created event not firing.

Get help using Construct 2

Post » Mon Aug 20, 2012 2:04 pm

Is the On created event only fired when you create an object through an action? Doesn't seem to be working on objects that are already placed in the layout.

Is there a workaround for this?

Thanks
B
5
Posts: 15
Reputation: 737

Post » Mon Aug 20, 2012 3:37 pm

Use 'on start of layout'?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,390

Post » Mon Aug 20, 2012 4:04 pm

[QUOTE=sqiddster] Use 'on start of layout'?[/QUOTE]

Objects can be created during gameplay as well as present at the beginning. So I would rather not duplicate actions.

Surely it makes sense for an objects Created event to be called if it 'created' when the layout starts?
B
5
Posts: 15
Reputation: 737

Post » Mon Aug 20, 2012 4:10 pm

[QUOTE=Baked]Objects can be created during gameplay as well as present at the beginning. So I would rather not duplicate actions.[/QUOTE]

I guess the objects are created before the events run, so you could either create the objects 'On start of layout' in the event sheet instead of placing them in the editor, or you could just use an OR-event:

'On start of layout' -OR- 'On created'
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Mon Aug 20, 2012 4:33 pm

or try:[code]
on start of layout
for every Sprite
add local variable old_x and set it to Sprite.X
add local variable old_y and set it to Sprite.Y
destroy Sprite
create Sprite at x = old_x, y = old_y[/code]
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Mon Aug 20, 2012 4:42 pm

Thanks guys, I will have a look at those solutions.

But am I the only one that thinks the object created event should be called for each object that is already in the editor?
B
5
Posts: 15
Reputation: 737

Post » Mon Aug 20, 2012 5:04 pm

But you still need to place at least one instance of the object on the layout (outside, whatever place you want) to create it on the runtime. If you don't place the object, you'll not be able to reproduce any behavior for it (and I think your game will also bug).
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,187
Reputation: 18,261

Post » Mon Aug 20, 2012 6:21 pm

game will do an alert if it can't find at least one instance in layout, so yes, you must have at least one instance of every sprite created NOT by events. I think a quite good solution would be to create a layout with all game sprites, and never go to that layout if you cannot bare having instances outside standard layouts and destroying them on start :)

as for onCreated - well create object event triggers on created - that's obvious. already created objects are not created during the game, they are there from the beginning - that's why the oncreated doesnt trigger I think.

hope that helps
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Mon Aug 20, 2012 6:53 pm

[QUOTE=ranma] game will do an alert if it can't find at least one instance in layout, so yes, you must have at least one instance of every sprite created NOT by events. I think a quite good solution would be to create a layout with all game sprites, and never go to that layout if you cannot bare having instances outside standard layouts and destroying them on start :)

as for onCreated - well create object event triggers on created - that's obvious. already created objects are not created during the game, they are there from the beginning - that's why the oncreated doesnt trigger I think.

hope that helps[/QUOTE]

Yes, I use the same technique placing all objects in an unused layout.

As for onCreated; technically the instance of the object must be created when that layout loads the objects you placed in the designer.

Anyway, I've just joined the onCreated and layoutStart events with an 'or' as that seemed like the most elegant solution.

Thanks again.Baked2012-08-20 18:53:43
B
5
Posts: 15
Reputation: 737


Return to How do I....?

Who is online

Users browsing this forum: badmoodtaylor, Megavolt and 12 guests