How do I Set ID to Specific Instance Variable

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

    Today i'm looking for something specific on Instance variable.

    I have create an Object ( We will name it Door ) with two Instance variables : ID_ and On ( ID_ Can have multiple Value and On can only have 0 or 1 )

    Then what i looking for is :

    When i create a new object ( Door ) on the layer i would like to set his ID_ variable to a new one than the previous one, for exemple :

    If i have one object ( Door ) on the layer with the ID_0, when i create a new object ( Door ) on the Layer i would like his ID_ was different than the previous one ( ID_1 ) and this evry time i create a new object ( Door ) on the layer. ( ID_2, ID_3, ID_4, etc... )

    This is the first thing i need, so now the second.

    If i interact with this object ( Door ) i have add an action for set the On variable to 1, then if i have multiple object when i interact with one it will set all the object ( Door ) to 1, but i want to set this variable only to the object ( Door ) i interact with.

    Hope someone have the solution.

    Thank you =D

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This tutorial might help:

    https://www.scirra.com/tutorials/806/instance-variable

    instead of setting the id to id_0 id_1 etcetera why not set it to 0, 1, 2,

    you could have a global variable Doorscreated

    and have an event:

    • on door created
    • door set variable id : Doorscreated
    • system add 1 to doorscreated
  • What littlestain said.

    or and tread carefully

    You can also use

    set id to door.iid

    IID

    [quote:15wmlg1c]All objects at runtime have an index ID assigned, which is the number of the instance within its own object type. It is returned by the object's IID expression

    So you create 4 doors the iid is 4.

    So if you creating it at runtime, then this is a great way to add 1 on each new instance.

    Click on door

    Set door.open to 1

    It will set that instance door.open to 1.

  • Thank you Dutoit and Stain,

    I have modify the method of Stain and try with your method Dutoit, the two works fines, now i have to make it work for the second feature, i think i have to modify the code, because i use particle on the second feature and position them on the object X and Y so i have to find a way for make when player activate the action ON that's create the particle on the Activated Object and only him ... Then the other if he activate them ...

    Thanks Bro =)

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