Doubt about UID and instances.

Get help using Construct 2

Post » Sun Feb 02, 2014 2:39 pm

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:

code

And the project's layout is:


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?Heptagono2014-02-02 14:47:05
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Sun Feb 02, 2014 3:06 pm

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.mindfaQ2014-02-02 15:07:16
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Thu Feb 06, 2014 6:05 pm

mindfaQ, thanks a lot for your answer. It has given me the key to solve the problem. Two thumbs up!
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Thu Feb 06, 2014 6:06 pm

Tanks! It works
B
17
S
4
G
1
Posts: 105
Reputation: 1,874


Return to How do I....?

Who is online

Users browsing this forum: sanjeev19jha, totoe, zenox98 and 10 guests