How do I replicate one instance variable value into a different instance?

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • This seems simple but I just can't figure it out.

    Situation: I have a bunch of tiles that are all instances of a tile object. I want one instance to automatically become the same color as as another instance when it changes.

    I set up instance variables Rcolor, Gcolor, and Bcolor in the tiles.

    On every tick each tile sets its own color using Set color to rgbEx255(self.Rcolor, self.Gcolor, self.Bcolor)

    Now I just need to have specific instances automatically set their variables to be the same as another specific instance.

    As a sub of the Every tick event, I have Pick Tile where Tile.UID=##, and then set Rcolor to... and this is where I'm stuck. I can't set it to Tile.Rcolor because it just picks the value of the same tile. I can't set it to Tile.UID=different## because then I can't seem to also choose an instance variable from that tile.

    How do I do this?

  • If you know the IID of the tile you want to copy variables from, you can do this:

    Pick Tile instance -> Tile set Rcolor to Tile(n).Rcolor

    Where "n" is the IID of another tile.

    .

    Another method is to use a family. Create a family with the Tile object. This will allow you to pick two Tile instances in the same event:

    Pick Tile instance
    ..Pick TileFamily instance
    .....Tile set Rcolor to TileFamily.RColor
    

    Note, that for this to work you'll have to define instance variables on the family. This tutorial may be useful:

    scirra.com/tutorials/535/how-to-upgrade-an-object-to-a-family

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks dop200.

    I figured using IID would be a solution, but I can't figure out how to tell what the IID of an instance is. The properties tell you the UID but not the IID. How do you find that number?

    I'll explore the family method as well. I haven't done anything with families yet. Thanks for the tutorial link.

  • Instance with the lowest UID has IID=0, next is IID=1 and so on. You should also be able to see IIDs in Debug Mode. Note, that IIDs are not permanent, if you delete an instance, IIDs for remaining instances may change.

  • Debug mode, yes... I don't know why I didn't think of that. Thanks, that gets me moving again.

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