How do I make less code for multiple characters?

Get help using Construct 2

Post » Thu Oct 27, 2016 3:37 pm

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.
B
7
S
2
Posts: 28
Reputation: 483

Post » Thu Oct 27, 2016 4:54 pm

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.
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800

Post » Thu Oct 27, 2016 5:30 pm

There you go, 3 events for all characters : https://dl.dropboxusercontent.com/u/495 ... chars.capx
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800

Post » Thu Oct 27, 2016 7:47 pm

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

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


Code: Select all
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)



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.
B
7
S
2
Posts: 28
Reputation: 483

Post » Thu Oct 27, 2016 7:58 pm

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.
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800


Return to How do I....?

Who is online

Users browsing this forum: pegasus6464 and 27 guests