I’m working on a turn-based combat system. The goal is to have each enemy (of up to four) go through the attack event group before cycling to the next enemy until there are none left that haven’t attacked, at which point the enemy turn is ended. At the beginning of the turn, I check if each enemy slot is filled (enemy is alive). If a slot is full, I add its corresponding value (i.e., “2” for slot2) to an array variable named Combat.EnemyCounter. I then have a “for each child of Combat.EnemyCounter event” as the superordinate event of my attack sequence. Enemies are structure variables stored as children of an array for each enemy slot.
The part I’m struggling with is getting the proper damage numbers for each enemy during the enemy’s turn. Currently, I’m using the function “Enemies.EnemySlots[Combat.EnemyCounter[child]][0].DMG*10”
to get numbers for damage. This works fine if the enemies are all of one type, but if they are mixed it will choose the first available enemy and base damage numbers for all enemies in the group on that variable. Bandits deal two damage, while Miscreants deal one. In a group with an even split, I would like the total damage dealt to be six. Currently, it will be either four or eight, depending on which enemy comes first in the group. After the first enemy is killed, damage numbers default to the second enemy’s base damage stat, so on and so forth.
I have tried storing the child variable from the “for each child” event in another variable, and then referencing that variable to get damage numbers, but it caused the enemies to stop attacking after the first one was killed. I feel like I’m overlooking something obvious, but unfortunately, I don’t have enough experience to understand how these functions are supposed to work
Thank you for the response! I haven’t tried that. To be honest, I have no idea how object variables work or where I would even get started rebuilding what I have here using them. I feel like I am so close to a solution here, but I just can’t figure out how to get it working as intended. I may try restarting from scratch and learn how to use object variables if a bit more tinkering doesn’t give me a solution.
I tried modifying the “for each child” event to store the children in the array variable Combat.Test, and using the function “Enemies.EnemySlots[Combat.Test[0]][0].DMG”
to get damage numbers for each enemy as its turn arrives.
Once an enemy has finished its attack, I have it set to clear children of Combat.Test in the hopes that when the next enemy index is added, it will be placed in Combat.Test[0]. Unfortunately, this resulted in all enemies ceasing to attack once the first enemy is dead. When the routine is being run, does the “for each child” event store one child before running the sub-events, then store the next and run them again, or does it store all of the children at the beginning and then run the script once per child? I guess I’m just confused that I can’t seem to reference the child itself
I did it! I’ll leave the solution here for anyone who might stumble upon it. I ended up using a variablechildcount for the Combat.EnemyCounter array, and storing the count in Combat.DMGRefCounter (I know the names are getting ridiculous, but I have too many counting variables). This tells you how many children are in the array, and since the children of the array themselves contain the index numbers for whichever enemy slots are full, I was able to just count through the children of Combat.EnemyCounter to get pointers for damage numbers. The final monstrosity is “Enemies.EnemySlots[Combat.EnemyCounter[Combat.DMGRefCounter-1]][0].ATK*10”.