Page 1 of 1

### How do I create a battle system with Arrays and Functions?

Posted: Wed Aug 02, 2017 5:27 pm
I'll keep it brief. I'm trying to create a battle system using an array, groups and functions.

I have an array to set the order of actions determined by the players stamina stat (speed).
Once an action is completed it updates the list. But after the first action the games stops. But when I run in de-bug mode, I can see it's not mapping WHO should attack. Just how much stamina they have. Which brings up the question of how does the first turn play out if it's not mapping who should go next in the first place? I don't understand this at all. I just want make a game. If anyone could nudge me in the right direction it would be greatly appreciated.

https://mega.nz/#F!9ZNkiCbQ!UP76ob_Y_IW0gGPw3afFBQ

### Re: How do I create a battle system with Arrays and Function

Posted: Wed Aug 02, 2017 6:13 pm
Trigger once doesn't work alone. You need some other variable to check that that value is checked just once. Your Player1 group is constantly calling those top events (#7), which is why the menu selection gets reset.
Also checkturn() always checks TurnOrder(0,0), but it doesn't change in the context of Player1.

### Re: How do I create a battle system with Arrays and Function

Posted: Wed Aug 02, 2017 8:54 pm
@blackhornet
Thank you for the response and yes, I wanted to make it work like that, so it only checks the 0,0 and after every action is completed it will shift everything up, so 1,0 is moved to 0,0. 2,0 is moved to 1,0 and so forth. Will that work or will I have to check 0,0 then once the move is executed shift to 1,0 manually? So rather than replacing 0,0 with 1,0 , I just check 1,0 then 2,0 in order are separate events? I'd prefer to do the 0,0 method since it'll use less events but if that doesn't work i'll change method.

I thought that the moment you enabled the group the "Trigger Once" would trigger it the moment the group is activated once. Guess not.

Thank you for the help. It's very much appreciated.

### Re: How do I create a battle system with Arrays and Function

Posted: Wed Aug 02, 2017 9:21 pm
This is a start: http://www.blackhornettechnologies.com/Construct2Stuff/rpghelp_BHTc.capx
You can pop items off of the top of the array, so they move up. Watch out for running out of items though.

### Re: How do I create a battle system with Arrays and Function

Posted: Wed Aug 02, 2017 9:54 pm
Upon playing It's not quite what i'm going for, the turn variable was for testing so I could see in de-bug mode what was currently being done. I'm testing 1v1 but I want it to be changeable so it could be 3v3. However the way you've mapped the Array is that it destroys itself when I want the game to keep going until someone has died. I haven't implemented that since this is just a turn based test, I wanted to just get an infinite battle system which every time you launch the game the stamina stat in different. so sometimes the enemy will outpace you, other times it won't. Once that's working i'll implement more enemies so it's proper.

The way I've mapped it is that X contains the enemy type (1 = player1 , 2 = player2, 3 = player3, 4 = enemy1, 5 = enemy2, 6 = enemy3). And Y contains the enemies stamina of the player/enemy. The reason I'm using Arrays is because it saves me makes 10 million variables and it has a nice sort feature. So I can sort by the y which is the stamina stat. But my question is, if I sort the Y will it move the X too? because otherwise player 1 will end up with someone else's stamina.