About families and variables

For questions about using Classic.

Post » Thu Jan 05, 2012 5:09 am

In my example we have several kinds of enemies, all in the enemy family.
Now every enemy has the private variables for OriginalHeight and OriginalWidth.

These variables are set to their respective height and width values of enemy objects and instances at the start of layout, once.

Now in theory I thought, it will set the variables individually for every object in the enemy family. However what I can see in Debug Mode is that only one kind of enemy in the enemy family gets the values set. The other kinds of enemies have the variable, but don't set any value, it stays zero.

My confusion comes from the fact, that despite this, one of the formulas I used, containing these variables values, still works for every enemy type.

I basically set the position of the player in a certain case to: "enemy.X - enemy.OriginalWidth/2 - player.Width/2" and the same for Y and Height.
Divided by 2 because their hotspots are in the middle. I want to position them exactly next to each other, and both sprites so to speak with their feet, the bottom of their sprite at the same Y position.

The enemies purposefully for testing this have different sizes.
So I don't understand why, although their variables basically have the value 0, the positioning of the player still works fine for the other enemies?


Thank You in advance.
B
3
G
1
Posts: 70
Reputation: 615

Post » Thu Jan 05, 2012 6:40 am

Variables are a bit buggy for families. Might try the system "for each" applied to the enemy family.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Thu Jan 05, 2012 6:54 am

Yes, it is an issue. One thing you have to do is using the family manager for adding private variables to a family - and even then there are odd behaviors sometimes.
So, never add a pv to an object and then add it to a family. Instead, add it to the family, and if this pv already exists for the other objects in the family, it will ask you if it should add the pv for that object automatically. The cleanest way would be to have all the objects for the family without any private variables, then add them to the family and then add the pv using the family manager.

Or, just try as newt said :)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Jan 05, 2012 10:27 am

Thanks for the fast reply and letting me know, guys!
I'm going to give it a try later.

Although weird that it works, without seemingly giving the value to the variable in the other enemies, at least not visibly so in Debug Mode.
B
3
G
1
Posts: 70
Reputation: 615


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest