About families and variables

This forum is currently in read-only mode.
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • 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. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Variables are a bit buggy for families. Might try the system "for each" applied to the enemy family.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 :)

  • Thanks for the fast reply and letting me know, guys! <img src="smileys/smiley1.gif" border="0" align="middle" />

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)