How do I create an object with diff instance variable value

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello everyone

    Well, basically i have one building, when you click a button it creates an object, when you click again it creates another object

    at some point every oject can only be used once

    My idea is to put on all the objects as they are the same sprite the instance variable "Unitname" wich is a number

    My question is then: how do i make each object created have it's own isntance variable "Unitname" changed without changing everyone elese's "Unitname"?

    It would be like Set value: Unitname+1 but that would change all the sprites isntance variable, help please =(

  • If you set the instance variable right after the create, it will only affect the new instance.

  • You need to 'Pick' the right instance, check out the pick event in the engine, it offers a few different ways you can use depending on your situation.

  • You could also refer to the object in the condition first before adding to the instance variable in order for it to reflect on THAT object's variable

    For example if you put:

    On object creation- Set unitname +1

    That will add 1 to that object, not the ones already in the layout, just make sure it refers to the object you want in the conditions before changing the instance variable.

    I'm utilizing the same for some platforms i need to change color, at first i had the same issue until i realized it needs the above, so i made a condition where if in collision with the platform it added to the instance variable. I learned that it only adds to that one object you collisioned with, not the others.

  • Well i made a little more research, and i have come out with this

    Thik it will work, gotta make some tests, thanks for your comments, i will try thm and any other idea left on this psot, and thanks for the quick answering =D.

    --------------------((EDIT))-----------------------

    Yep, it works =) thans alot =D.

  • I'm not 100% clear on what you are asking for, but if you just want your objects numbered sequentially, you could look at sprite.IID, an index (number) starting at 0, assigned to each created object. Each IID range is separate for every object type.

    https://www.scirra.com/manual/130/common-features

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks codah, i've checkd it, it's as well as good for what i needed when i first opened this post, since i didn't know about IID, but now with that info and the "debug" i can keep track of them, i'll still use the methood i posted above on the img for different instance variables.

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