How do I use families correctly

0 favourites
  • 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

    Keyboard / Key code heroes.btn_left is down / Simulate Platform pressing Left[/code:2300vcv7] 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.
  • Try Construct 3

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

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

  • 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"

  • 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

  • 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...).

  • 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.

  • 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

  • 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.

  • 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 ?

  • 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.

  • Exactly what I needed !

  • I found a way to do this but it's still a bit bulky. I'll try to trim the script tomorrow but for now it still saves you the hassle of writing separate events for each player. Also it works pretty well. Left click to select player 1 and right click to select player 2. The first uses WSAD + space and the second uses the arrows and num zero. You could easily add as many players as you like provided you have enough keys for them.

    https://drive.google.com/open?id=0ByMnh ... 3dnNnBtNDg

    If you have questions let me know.

  • Hi again,

    I tested on my project and it works perfectly, thx again.

    BUT, 2 things are annoying me : if I follow your exemple, I need to reproduce every animation (and behavior, and condition, and...) to each player, for every character. Let's say we have 8 characters and 4 players, that means I have to copy 32 times the same code. I'm sure we could find a better way to optimize it. Besides, for each animation, I need to import again and again every frames, check that the collison polygons, and the image points are the same for each player (I didn't find a way to copy/paste an animation from an object to another).

    I tryed to clone the object player1, but now it seems that the player2 (the clone) is ALSO a player1 object.

    In brief, isn't it possible to think in reverse order ? I mean, create each character, and then, give them the inputs of the right player ?

    (I apologize if it's going to be a little bit off topic, if I need to, I will reopen in a more appropriate part of the forum)

    Edit : Thank you RageByte, I will look at your file.

    Edit2 : wow, it looks very impressive and efficient. I need to take my time to understand every line BTW, thak you for the comments !

  • Ok, I redid most of it. It does basically the same thing in a more flexible way and less events. It should even be more CPU efficient. This new design relies on text variables and the tokenat, tokencount and find expressions to search through, parse and manipulate the text. The point is to store and access multiple variables in a single text variable for higher flexibility. It's harder to grasp but I put a lot more detailed explanations in there. Hopefully they will help but as I said, feel free to ask.

    https://drive.google.com/open?id=0ByMnh ... 3dnNnBtNDg

    EDIT: I accidentally used the latest Construct beta r236 for this so you'll need that to open it.

  • Nice control scheme RageByte with clever use of families.

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