Noob question about instance variables

Discussion and feedback on Construct 2

Post » Wed Oct 10, 2012 4:27 pm

Hi there,
I've looked anywhare into the forum but found nothing about it. Maybe the question is too silly, anyway I'm really puzzled about this strange behaviour.

As you can see in the image, in step 17, I'm trying to assing the value of a variable of the sprite instance which triggered event to a variable of the just spawned new sprite (a different one).



The strange behaviour is that in the scope of event the variable seems set correctly, but when I try to check it in the subsequent event (18 and on) it is always 0: no assignment was done.

Please, someone there can help me to get what's wrong?

Thx
B
6
G
1
Posts: 10
Reputation: 1,048

Post » Wed Oct 10, 2012 5:25 pm

There are a couple of problems here:

When one object spawns another of the same type, like
[code]Spr_Steady: Spawn Spr_Steady[/code]
the original sprite remains picked and the newly created one isn't. So the next line:
[code]Spr_Steady: Set nColor to Spr_Brick.nColor[/code]
is setting the nColor var of the old Spr_Steady, not the newly created one.


The other problem is that the 'on created' trigger is called immediately when you create an object. So you have the action in Event 17:
[code]Spr_Steady: Spawn Spr_Steady on layer 0[/code]
then all of Event 18 runs and then the next action in 17:
[code]Spr_Steady: Set nColor to Spr_Brick.nColor[/code] runs.
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Thu Oct 11, 2012 1:39 pm

Thank you very much!!

I'll apply all your suggestions.
B
6
G
1
Posts: 10
Reputation: 1,048


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests