How do I use families correctly

Just started using Construct 2? Post your questions here

Post » Fri Sep 30, 2016 10:25 pm

Greetings,

I'm trying to create a game with several characters, all of them sharing the same controls (one by player). I don't want to repeat all my code for each character, so I tried to gather all the heroes objets on a "heroes" family, and write in my scripts sheets only events like "heroes / set animation to "walk" (all the characters animations share the same name for the animations).
Then, I add many variables and behaviors to that family, but some of those variables need to be personalized. For exemple, I declare in my events sheet
Code: Select all
Keyboard / Key code heroes.btn_left is down / Simulate Platform pressing Left
where btn_left is the variable I need to set for each character. I tryed to set them in the properties of the characters, but they then override the family (heroes) variables. I tryed to set them at the start of the layout (character / set btn_left to 81), but it still doesn't work.

How should I use the Families properly to use the same events for all my characters, and personalize their variables ? Or if it's not appropriate for what I'm looking for, what should be the best solution ?

Thanks for your help.
B
7
S
2
G
1
Posts: 14
Reputation: 533

Post » Sat Oct 01, 2016 9:46 am

Is this a single player game where you can choose different characters? You should only have to set the controls once for the player. If it's not that type of game then please explain more about the game so I can give some advice on whether to use families.
B
46
S
16
G
79
Posts: 2,170
Reputation: 46,857

Post » Sat Oct 01, 2016 7:42 pm

Thank you, I'll try to be more precise :
  • It's a local multiplayer game,
  • up to 4 players.
  • Each player can chose from several characters.
  • All characters have got globally the same behaviors. They all run, jump, attack, lose life, collect coins... (of course, they all have got special skills)
  • Because they are all quite the same, but individual characters, they need to use their own buttons, their own life bar, etc.
In my mind, I wanted to declare the events only once for all heroes, in a family (?), something like Keyboard / Key code heroes.btn_left is down / do something".
And then, set the variables like "player2.btn_left = 81"
B
7
S
2
G
1
Posts: 14
Reputation: 533

Post » Sat Oct 01, 2016 8:11 pm

I would just set up 4 lots of controls and if 1, use control set 1, if 2, use control set 2 etc, where 1, 2 are just player IDs. Whether the players are separate objects or 4 instances of the same object you can still assign a player ID or maybe even use UID. Families are not going to work here because you're trying to apply controls to different things within the same family instead of all but it's fine as you don't really need them. Families will be useful though for cutting down on the events for taking damage and the gameplay things you listed etc
B
46
S
16
G
79
Posts: 2,170
Reputation: 46,857

Post » Sun Oct 02, 2016 9:55 am

Hmm, I get the idea, but can you show me a concrete exemple ?

Let's say I only need 2 players (player1 and player2), 2 selectable characters (knight and wizard), and 2 events (go to left, and go to right).
All characters' animations share the same names (walk_left and walk_right).
What do I need to write in my events sheet to not repeat my code ?
What is happening when player2, who previously selected knight, is moving to the right ?

When I'll understand this, I think the most part of my project will be easy (well, I hope...).
B
7
S
2
G
1
Posts: 14
Reputation: 533

Post » Sun Oct 02, 2016 2:23 pm

When I'm doing controls it's as simple as that : https://dl.dropboxusercontent.com/u/495 ... trols.capx

I also added a character select so you'd see how I would start with the basics of picking a character.

You don't use families for this but I've added the two events underneath to show how you could use families, i.e. when any character's health is 0 then destroy, this saves you from typing out when wizards health is 0 then destroy, when knights health is 0 then destroy.

The setup of the controls is really based around how your game works. If player 1 selects wizard, the wizard will spawn OK but which controls are they using, is it always the same set of controls for player 1 and player 2? It's easy to set up with player IDs.

Regarding the last question, that's for you to decide I guess? You said it was local co-op so I guess the controls are set to certain buttons.
B
46
S
16
G
79
Posts: 2,170
Reputation: 46,857

Post » Sun Oct 02, 2016 4:36 pm

Thank you again.
The event sheets were clear enough to let me understand. I can see that you repeat the controls for all characters, so I suppose there is no way to declare them only once, and change a simple variable. Too bad :)
Last edited by ralf5543 on Sun Oct 02, 2016 4:52 pm, edited 1 time in total.
B
7
S
2
G
1
Posts: 14
Reputation: 533

Post » Sun Oct 02, 2016 4:42 pm

There might be but I do it this way, especially for the controls. I don't see any reason to look any deeper into it because the premade behaviour handles everything.
B
46
S
16
G
79
Posts: 2,170
Reputation: 46,857

Post » Sun Oct 02, 2016 5:01 pm

One last thing, I I may. In your exemple, the controls are based on the selected character (knight, wizard), not the player. I wish the player 1 could control any charatcer with left/right, and the player 2 with A/D. Is it possible ?
Oh, and I suppose your health variable is actually common to all characters. So if knight and wizard are playing together, they die together ?
B
7
S
2
G
1
Posts: 14
Reputation: 533

Post » Sun Oct 02, 2016 5:35 pm

There are lots of ways you can do it. This is another way : https://dl.dropboxusercontent.com/u/495 ... rols2.capx

Here you assign player 1 a character and set the anims corresponding to the character and player 1 always has the same controls.
B
46
S
16
G
79
Posts: 2,170
Reputation: 46,857

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest