Noob question about instance variables

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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).

    <img src="" border="0" />

    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?


  • There are a couple of problems here:

    When one object spawns another of the same type, like

    Spr_Steady: Spawn Spr_Steady

    the original sprite remains picked and the newly created one isn't. So the next line:

    Spr_Steady: Set nColor to Spr_Brick.nColor

    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:

    Spr_Steady: Spawn Spr_Steady on layer 0

    then all of Event 18 runs and then the next action in 17:

    Spr_Steady: Set nColor to Spr_Brick.nColor


  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you very much!! <img src="smileys/smiley31.gif" border="0" align="middle" />

    I'll apply all your suggestions.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)