0 Favourites

Doubt about UID and instances.

  • Hi!

    I am trying to make this buttons change the values of some gobal variables.

    By now, all the buttons are the same object, and I'm calling each instance of them by looking at each's instance UID.

    So, the code looks like:

    <img src="https://www.dropbox.com/s/5rdxcz4u8ya7vkk/code.png" border="0">

    code

    And the project's layout is:

    <img src="https://www.dropbox.com/s/bxnukiv0kbabqba/layout.png" border="0">

    layout

    Unfortunately, the idea doesn't works and even clicking on the buttons and the variables don't change. Perhaps the code isn't correct.

    Here is the project file:

    test_instances.capx

    I presume that picking an instance n? is the same as select its UID.

    Any advice on why buttons don't change the variables as they're supposed to do?

  • UID and IID are different from each other. You pick by IID.

    UID is unique.

    IID only is unique along all instances of an object and gets automatically assigned starting at 0 and counting up.

    So your code would need to be

    pick instance 0 of button

    pick instance 0 of text

    pick instance 1 of button

    pick instance 1 of text

    Or you swap it with picking by UID, then your code would work as well.

    I probably would give each object an instance variable though and identify them with the help of this variable. So for example the buttons get a variable named buttonID, you set it to a different value for each button and can pick them with by comparing the instance variable.

    This will be a more descriptive way of doing things and could help you to understand what exactly the code is doing, when you come back to it later on for whatever reason.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • mindfaQ, thanks a lot for your answer. It has given me the key to solve the problem. Two thumbs up!

  • Tanks! It works

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,380
rexrainbow's avatar
rexrainbow
Unread hot topic
0 Favourites
[PLUGIN] Instance Group
50 17,113
sagispin's avatar
sagispin
Unread hot topic
47 11,343
Rable's avatar
Rable