How do I Set ID to Specific Instance Variable

Get help using Construct 2

Post » Mon Aug 25, 2014 12:53 pm

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
B
21
S
9
G
3
Posts: 70
Reputation: 2,722

Post » Mon Aug 25, 2014 1:16 pm

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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Aug 25, 2014 1:42 pm

What littlestain said.
or and tread carefully
You can also use
set id to door.iid
IID
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.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Aug 25, 2014 9:03 pm

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 =)
B
21
S
9
G
3
Posts: 70
Reputation: 2,722


Return to How do I....?

Who is online

Users browsing this forum: NN81 and 8 guests