How do I make less code for multiple characters?

0 favourites
  • 5 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • www -dot- cazualnoob -dot- com/web-games/ (second game file)

    So, I want to have about 15-20 controllable characters, but am I really going to have to make all the code for walking for every single one of them?

    I'm aware of functions and loops, but I don't know how I'd get them to help me in this case.

    I'm aware of families, but still don't have the paid version just yet. Not sure if this is the answer to my problem.

    Under the "movement" group, for example, there are 2 more characters that don't have pathfinding coded. I want to know if I can make all the characters share the same code for pathfinding (along with many other future things).

    Any ideas or suggestions would be appreciated.

  • You could probably do it all in a few events with families. You would use a family instance variable for the selected character, set this to true when they have been clicked on or selected at the start of the game. Then you could say character(family), selected=true, find path to mouse.x,mouse.y, character(family) move along path.

  • There you go, 3 events for all characters : https://dl.dropboxusercontent.com/u/495 ... chars.capx

  • That would definitely the way to get groups to walk together.

    I was thinking of something closer to a php function like:

    function walkingFunction ($character, $x_coord, $y_coord){
    system find path
    $character on path found -> move along path
    $character on path arrived
    }
    
    **make any 1 character move**
    call walkingFunction(character15, 150, 300)
    [/code:f0xmzf9o]
    
    As far as I know right now, construct doesn't really have a way to do this.  Carrying parameters to do repeated actions for different sprites.
    
    It looks like families would be the closest thing to get me there.  I'll have to get it before I can get too much farther.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can pass parameters through a function like that but I don't really know what your game is meant to do. Your logic had you selecting a character and then having them move on right click to a position so I just based my logic off that.

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