Why doesn't this work as intended, and how do I fix it?

Get help using Construct 2

Post » Wed Aug 31, 2016 5:55 pm

Image
"explosion.size" gets set to 0.5 (in game), but the scale doesn't update on spawn. Why?
B
10
S
4
Posts: 24
Reputation: 804

Post » Wed Aug 31, 2016 6:10 pm

Because set scale to explosion.size happens at the same time as the object is created, before you actually set size. So it will be scaling at whatever size was before you set it to 0.5, the default value.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Wed Aug 31, 2016 6:17 pm

i moved the set scale to the "on right click" and it works
Last edited by Mubot on Wed Aug 31, 2016 6:32 pm, edited 2 times in total.
B
27
S
5
G
1
Posts: 31
Reputation: 1,443

Post » Wed Aug 31, 2016 6:19 pm

plinkie wrote:Because set scale to explosion.size happens at the same time as the object is created, before you actually set size. So it will be scaling at whatever size was before you set it to 0.5, the default value.

That's what I thought. What's a good workaround, then? I'm trying to make it so that whenever I spawn that sprite I can specify it's size as well as a few other things.
B
10
S
4
Posts: 24
Reputation: 804

Post » Wed Aug 31, 2016 6:40 pm

Where create object is, instead call a function. Then in the function create the object, set its stats etc. You could also make use of parameters within the function so if you call "Create Explosion" (3). Then in the function, you can use Set scale to function.param(0). That way whenever you call the function, the scale size will always be that first param. It really depends on how detailed you want to go.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Wed Aug 31, 2016 7:04 pm

No workarround needed.

You can do things (actions) with a newly created objects, either right after the creation or in the 'on create' event.
You can NOT read things (expressions) from a newly created object until the next root-level event.
Picking depends on expressions (by UID is the only exception), so you can not pick a newly created object until the next root-level event.

You set the instance variable explosion.size to 0.5. Thats is possible, as said, its just an action. But read that variable is not possible until the next root-level event. 'On created' just runs as it is on the same time and place as the creation action. So it is no new root-level event.

How to do this the easy way? And that is not a workarround, that is just how things go.

Give the sprite an instance boolean 'JustCreated'.
Right after the creation action, set that boolean to 'true'.

Now just a totaly new event with the condition (root-event) ..
Condition > Sprite > Is boolean instance set > 'JustCreated'
Action > set 'JustCreated' to false.
Action > anything you want to do with/read from the sprite.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Sep 01, 2016 5:59 pm

99Instances2Go wrote:No workarround needed.

You can do things (actions) with a newly created objects, either right after the creation or in the 'on create' event.
You can NOT read things (expressions) from a newly created object until the next root-level event.
Picking depends on expressions (by UID is the only exception), so you can not pick a newly created object until the next root-level event.

You set the instance variable explosion.size to 0.5. Thats is possible, as said, its just an action. But read that variable is not possible until the next root-level event. 'On created' just runs as it is on the same time and place as the creation action. So it is no new root-level event.

How to do this the easy way? And that is not a workarround, that is just how things go.

Give the sprite an instance boolean 'JustCreated'.
Right after the creation action, set that boolean to 'true'.

Now just a totaly new event with the condition (root-event) ..
Condition > Sprite > Is boolean instance set > 'JustCreated'
Action > set 'JustCreated' to false.
Action > anything you want to do with/read from the sprite.

So that works, but now whenever the explosion sprite is spawned it there is a slight delay until the variables are updated, and thus a slight delay for the visuals as well. This, quite frankly, looks awful. Any other ideas?

EDIT: Actually, I came up with a workaround. I set the explosion to be initially invisible, then when the instance variables were to be read I set it the explosion to be visible. Thanks for the help up to this point!
B
10
S
4
Posts: 24
Reputation: 804

Post » Thu Sep 01, 2016 9:52 pm

Variables take time to set ? Okay. If you say so.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, David181 and 9 guests