I don't quite understand how private variables work yet

For questions about using Classic.

Post » Wed Jun 03, 2009 7:34 am

Hey folks,

I'm new to this whole Construct thing, but i've used similar programs like Game Maker. So far, i'm enjoying this program a whole lot more.

Anyways, i've been tinkering around a little and i have this little game where i want a bunch of physics objects to scoot around the screen from side to side. When they hit an object and their velocityx reaches zero (or close to it) they change direction. Problem is, the way i have it set up now, they all change direction at the same time and i don't know how to change the event sheet so that i change only the private variable of the object instance the event occurs for. (i hope that makes sense) How do i make it so that they function independently of each other?

To see an example, check out the cap below:
http://www.mediafire.com/?erwoijjnmzl

I would like this question answered so i can figure out how exactly events and private variables work with each other. But also, if you have better ideas on how to make these objects change direction when they hit a wall, let me know that too.

Thanks!
B
2
G
3
Posts: 52
Reputation: 954

Post » Wed Jun 03, 2009 10:28 am

Using 'System - compare values' is what's causing this. This will just calculate two numbers and compare them, ignoring the fact there are multiple instances of the sprite (so it just picks the first one and uses values from that). You should either use comparison conditions within the sprite object itself (which has a 'compare private variable' condition which respects picking), or alternatively, you can put a 'for each sprite' condition at the top of the event, which forces the compare values to run once for each sprite.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Jun 03, 2009 5:47 pm

Great! Using the "once for each object" system condition works perfectly.

I suppose to solve it by comparing private variables within the object there needs to be some condition statements under an object's physics tab (which i'm guessing is on the todo list for the next Construct version) then i could just compare "object[physics].velocityx" with the object's private variable.

Thanks for the help!
B
2
G
3
Posts: 52
Reputation: 954

Post » Wed Jun 03, 2009 6:36 pm

If you want to pick an object by value comparison, store the value in a private variable (with (ALWAYS>>set VARIABLENAME to VALUE) and use "compare a private variable". it will pick instances which meet the condition.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Thu Jun 04, 2009 3:24 pm

Use the 'Pick by comparison' condition of Sprite, then enter (for example):

Sprite[Physics].VelocityY
equals
..

This will pick all instances which match it.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests