Copying a value on object-creation.

Get help using Construct 2

Post » Sat Nov 10, 2012 3:46 pm

If you're doing it like this:

System: Create EnemyShip
EnemyShip: Set Iconframe to 5

then after the create action it jumps to the 'on created' trigger and runs the code there and then goes on to the next line 'set Iconframe'. So the variable won't be set until after 'on created' runs. I'm guessing that's what's happening.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sat Nov 10, 2012 6:40 pm

This might be something to do with the fact that all of this is happening inside an 'On Created' event in the first place.

What happens is, when my ship is created, it hops to the 'On created' code for the ship, which then creates an icon to accompany it. So the code above is itself inside the ships 'On created' code.

So the ship is created, it then creates the icon, it then sets a variable to the UID of the icon, so that they stay together and then, finally, it attempts to set the icon to an animation frame, as indicated by a variable in the newly created ship. That final part is the part which doesn't work, the rest works perfectly.

So what I have is.

Ship : On created : System Create 'Icon' (works)
                    Set ship variable to the new icon's UID (works)
                    Set the icon's frame to a variable which is entered in that ship-type in the editor (doesn't work).

If I remove that third line and put it into a 'System : Each tick' event, it then works fine. Meaning that the code to set the animation from the ship's variable is ok, it just won't do it during the creation process of the ship. It's as if the variable isn't assigned until after the 'On create' or something.

I am aware of course that the code would hop out to do an extra 'On create' for the icon, except in this case, I have no code for that. Not sure if the system hops out to do it's own internal stuff, but it hops back in and completes the 2nd line with no problems, just not the third line.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sat Nov 10, 2012 8:48 pm

Ah you're setting the variable in the editor. Sounds like it should work then. Trying to think. If you haven't set the animation speed to 0 it could be playing through the animation and ending on the last frame. But you'd probably be able to see that happening.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sat Nov 10, 2012 9:04 pm

Ah HAH, you've hit the nail on the head, that's exactly what was happening. I couldn't tell because they all started off clumped ontop of each other, and they were all showing the final frame... since one of them (tpyical, the final, i.e TOP one) was SUPPOSED to show the final frame I couldn't see the others animating.

Good job mate, thanks for the help :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Previous

Return to How do I....?

Who is online

Users browsing this forum: Jarnopa, semaso and 15 guests