I only want to know how to go through all of the enemy units one by one without all of them moving/attacking at once. I have tried looping through them but that results in all of them moving at once. I put a Wait action with 1*loopindex into the loop and it kind of works but the results are unreliable (I can't really say why). I have also tried making a recursive "loop" but it also has its own problems. It does not seem to wait for other functions to finish or return a value.

For each unit, a certain amount of functions must be ran. So far I have implemented functions for checking if the unit can attack and if not then it moves. The movement function checks if path blocked and tries to go around. These functions work.

I want to pick enemy unit UIDs one by one and check if that particular unit can attack/move/etc and act accordingly.. then pick the next unit and perform the same checks. What do you mean by having them act independently with states?

Thank you for the reply! It seems to work.. But how do I do the random selection again for the remaining enemies? The selecting needs to be repeated and I would run into the original problem again I fear. In my game you can move all of your soldiers during your turn and not only one like in chess for example.

I'm using arrays containing unit UIDs for each team. The arrays are populated on start of layout. When the player changes turn, the game checks if the next player is AI. If it is AI, then loops player2_team.Width many times and picks a unit based on the UIDs in the array: player2_team.At(loopindex). After picking the unit, a series of functions are ran. These functions check if the current unit can attack or move to a tile.

This all works fine but it all happens so fast that the player will be confused. I want to find a way to delay the picking of the next unit.

You need to have an array that keeps track of all the units on a team 1 for players and 1 for monsters. for instance x 16 and y 8 z 1 16 slots 8 player vs 8 monster with each 8 variables UID,DoneTurn/TimeUnits,Health,HealthMax,Mana ect ect You should be looping through all of the active teams men to look for DoneTurn variable to see who has a turn still and giving them control at that point. It shouldn't be team changed be until your loop of Player.At(loopindex,2) (2 was DoneTurn in my example of the Y dimension) was COMPLETELY ran out without a single person showing a DoneTurn switch not thrown yet Then you throw all the Doneturn's back to 0 and switch teams.

Zamargo wrote:You need to have an array that keeps track of all the units on a team 1 for players and 1 for monsters. for instance x 16 and y 8 z 1 16 slots 8 player vs 8 monster with each 8 variables UID,DoneTurn/TimeUnits,Health,HealthMax,Mana ect ect You should be looping through all of the active teams men to look for DoneTurn variable to see who has a turn still and giving them control at that point. It shouldn't be team changed be until your loop of Player.At(loopindex,2) (2 was DoneTurn in my example of the Y dimension) was COMPLETELY ran out without a single person showing a DoneTurn switch not thrown yet Then you throw all the Doneturn's back to 0 and switch teams.

Thank you for the reply! What you are suggesting is basically what I'm doing. Looping through an array and checking if unit is active. Problem is that the loop goes through so fast... All of the AI unit movement and attacks become a simultaneous mess.

I have been planning the following: Let the loop go through fast, without moving or attacking, but recording all of the AI's decisions into an array, and then "playing" the array like a record with a 1 sec delay between every array entry. I tested a simple version of this and it worked but I noticed there is a major hurdle with this approach... Each AI unit would have to base their decisions on the new "record" instead of the current state visible to the player. I believe I may have to go this route anyway because it would be a nice feature to record all turns for later playback.

I was taking a dump and realized how stupid I have been. The answer to my question seems to be the 'Every x seconds' event. I put it into a group and activate the group when its AI's turn. Everything seems to work for now... Thank you all for taking the time to help!

Glad you got it to work! Okay, I understand now what is going on. When you are acting on behalf of a AI unit you need to remember to use System - Wait constantly because you are putting on an automated show just do it in between decisions, attacks, movement all of them so you get an effect like your watching something happen. Also put the "Scroll-to" behavior on all your AI and when it is that unit's turn flip behavior enabled on so your camera will leap around to the current computer unit acting. Tell me if you have any more questions.