Instance Variable

Get help using Construct 2

Post » Thu Jul 25, 2013 4:45 pm


Hi.

I've used 'instance variables' a few times, but I still don't quite understand it.

Can I use instance variables in this situation to re-use the object 'Sensor_1:'
by giving it the variable instance property?




I'd like the sensor object to do different stuff depending on which instance Player collides with. How do I check which instance of Sensor_1 Player is in collision with?
Thank you
B
13
S
1
Posts: 68
Reputation: 1,198

Post » Thu Jul 25, 2013 6:56 pm

Instance variables are used when you want a piece of data to be unique to an instance. In other words, if you have 10 sensors with an instance variable called "range" (for example), each sensor can have a different value for "range".

When a player object collides with a sensor, C2 will pick the specific instance(s) of sensor that collided with player. If you then access the sensor's instance variable, it will be specific to that sensor.
B
12
S
5
G
2
Posts: 59
Reputation: 3,859

Post » Fri Jul 26, 2013 1:57 am

Thank you.

So, making many new objects called Sensor_1 Sensor_2 etc is ok?
I have a kind of Construct-Anxiety with this kind of thing. I'm always worried that adding too many objects will 'slow it down'. (Am I just being supersitious?)
B
13
S
1
Posts: 68
Reputation: 1,198


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests