How do I create an object with diff instance variable value

Get help using Construct 2

Post » Mon Aug 04, 2014 9:16 pm

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 =( :?:
B
4
Posts: 6
Reputation: 207

Post » Mon Aug 04, 2014 9:26 pm

If you set the instance variable right after the create, it will only affect the new instance.
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Mon Aug 04, 2014 9:26 pm

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.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Mon Aug 04, 2014 9:32 pm

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.
B
11
S
2
Posts: 100
Reputation: 1,150

Post » Mon Aug 04, 2014 9:39 pm

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

Image

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.
B
4
Posts: 6
Reputation: 207

Post » Mon Aug 04, 2014 9:44 pm

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
Last edited by codah on Mon Aug 04, 2014 10:16 pm, edited 1 time in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Aug 04, 2014 9:57 pm

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.
B
4
Posts: 6
Reputation: 207


Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 5 guests