Creating and Destroying Objects

New releases and general discussions.

Post » Mon Jul 20, 2009 7:34 am

There seems to be an issue with Construct that I'm not sure if it can be worked around or if it's an oversight or if it's some kind of standard procedure I don't understand, but when I create an object (or destroy it, but I haven't tested that recently) any sort of event following the creation will be ignored. It seems to me any creation event is queued until all the code has finished, then the object is created.

The problem with this is for instance if I have several animation frames in a sprite but I want it to start on a particular one upon creation. The sprite will appear, though it will flash in its initial frame for a single tick. This is the visual indicator, any event such as setting its position or size following that event, but not within that event, won't affect the object until the next tick.

My great issue with this is the removal of being able to create several objects and have several conditions in the same event affect all the newly created objects. I have an event that follows now that if it's not 1 it will set all the values I want right after creation, then it sets the value to 1, and this event immediately follows the creation event, but is ignored until the following tick.

Now I might have several of these events through the code that have an identical condition, but as it sets the value to 1 it should only affect the ones I want, but if it doesn't work for the same tick it will always pick the topmost event for all the created objects of the same sprite. I used this approach of value-setting back with Multimedia Fusion as well, and that program created objects at the same line of code as the event that asks it.

It would be really nice and comfortable if objects were created and destroyed at their actual line of code rather than before each tick renders a picture, and I don't quite understand how this approach was chosen to begin with.

Thanks!

EDIT: A way around it is probably to make a single creation run several times over, but I think it still messes up the animation frames. And it just makes more sense for objects to create and have values set at the line of code where the event is.
B
5
S
2
G
3
Posts: 234
Reputation: 1,818

Post » Mon Jul 20, 2009 10:42 am

[quote="konjak":2rebc5ha]The problem with this is for instance if I have several animation frames in a sprite but I want it to start on a particular one upon creation. The sprite will appear, though it will flash in its initial frame for a single tick. This is the visual indicator, any event such as setting its position or size following that event, but not within that event, won't affect the object until the next tick.
[/quote:2rebc5ha]

I'm pretty sure I never experienced that. When I create a sprite, all the following events will be run in the very same tick as well. Wouldn't what you describe also mean when you created a sprite and destroyed it in the next event, it still appeared for one tick (which obviously doesn't happen). Or I'm not sure what you're getting at.

(Btw you can set the initial animation and frame in the properties. But I guess you knew that and need to change it dynamically.)

[quote="Konjak":2rebc5ha]It would be really nice and comfortable if objects were created and destroyed at their actual line of code rather than before each tick renders a picture, and I don't quite understand how this approach was chosen to begin with.[/quote:2rebc5ha]

Actually I'm pretty positive that's how Construct works: creating/destroying objects at their actual line of code. Otherwise many things I had tried in Construct would have failed horribly.
Then again I dunno I might want to see an example cap demonstrating the problem you described. Since I might just not get it after all...
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Mon Jul 20, 2009 10:51 am

It's always much easier if you have an issue (or think there's a bug) to post screenshots of events, or a .cap file, so others can suggest solutions. I'd be willing to take a look at your .cap file if you want.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Mon Jul 20, 2009 2:50 pm

Konjak, just set everything you want for the created objects on the action line right after the create/spawn action. Actions directly after a create/spawn action will pick the newly created one, and perform the actions on it.

eg.

create bloodpixels at kid.x, kid.y
.bloodpixels set height to 2
.bloodpixels set width to .height
.bloodpixels set value 'speed' to 2
.bloodpixels set animation frame to 3

any actions after the spawn/create event will affect the newly created object.

And what about destroying? I don't get what you mean about that.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Mon Jul 20, 2009 4:07 pm

I get what he's saying, and I've recreated the problem:

http://files.getdropbox.com/u/529356/creationism.cap

Click on one of the two buttons to create a box. The box should appear blue, without any flash of red.

The box on the left has the frame set to 2 (blue) within the create event, and it works normally.

The box on the right has an Always event after the create event that always sets it's frame to 2, but there is a flash of red when it's created.

Logically one would expect the box on the right to respect the order of events and change it's frame to blue in the same tick because of the Always event.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Jul 20, 2009 4:09 pm

[quote:34dudx44]http://files.getdropbox.com/u/529356/creationism.cap[/quote:34dudx44]
:shock:
B
3
G
3
Posts: 34
Reputation: 943

Post » Mon Jul 20, 2009 4:11 pm

:)

I was going to call it "intelligent design.cap" but I thought that was a bit too snarky :P
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Jul 20, 2009 4:36 pm

[quote="deadeye":3jzghr29]Click on one of the two buttons to create a box. The box should appear blue, without any flash of red.

The box on the left has the frame set to 2 (blue) within the create event, and it works normally.

The box on the right has an Always event after the create event that always sets it's frame to 2, but there is a flash of red when it's created.[/quote:3jzghr29]

:shock: I just was like "wth I tried smt like this and it didn't happen for me".
After reflecting one second (not necessarily about the problem at hand :P ) I remembered that in my example the object was created with key presses and not button clicks.

So I copied the creation-event of the right box, but with a "On key pressed" condition instead of the "On button clicked". I can see no flash of red!
Now has this problem something to do with how buttons work or am I going insane here?
Can anyone confirm it?
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Mon Jul 20, 2009 4:53 pm

[quote="Davioware":2ly3xmo5]Konjak, just set everything you want for the created objects on the action line right after the create/spawn action. Actions directly after a create/spawn action will pick the newly created one, and perform the actions on it.[/quote:2ly3xmo5]

I explained this approach is the exact one I use, and it doesn't work with this approach. It will start reading the code anew and look for the topmost of these events and execute it for all the created objects instead of just the one I want.

Maybe the "spawn" action works differently?

And as someone suggested that creating then immediately destroying works, of course it does, my point was they both execute at the end of the code, and that would mean it creates and destroys at the end of the code.

Destruction has done the same for me in the past, meaning I can have an event that says "destroy" then anywhere below have one that says "always + if object exists ---> play a sound" and even if the event is after it will play that sound one more time.
B
5
S
2
G
3
Posts: 234
Reputation: 1,818

Post » Mon Jul 20, 2009 5:08 pm

[quote="PixelRebirth":ps7crfaj] :shock: I just was like "wth I tried smt like this and it didn't happen for me".
After reflecting one second (not necessarily about the problem at hand :P ) I remembered that in my example the object was created with key presses and not button clicks.

So I copied the creation-event of the right box, but with a "On key pressed" condition instead of the "On button clicked". I can see no flash of red![/quote:ps7crfaj]

Huh. You're right, it does work fine with key presses.

Looks like there are TWO problems to solve in this thread now :P

And konjak, I guess you're going to have to upload an example of the problem because apparently I haven't recreated it at all.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 5 guests