- Home /
foreach, descending order. confusing question.
Alright so I have a list that has been organised in a descending order via a value that each script has.
Combatants = Combatants.OrderByDescending(x => x.Speed).ToList();
and I want to call a function in each object in the que one at a time. so I figured if I created an int and if it is equal to the qued objects placement in the list it is its turn to call the function. (At the end of the function it adds to the int. im unsure on how to go about this. I figured a foreach statement might work but unsure on how to incorporate it. Programming in C#
More code. So it sends a message to something in the que. This is in a FSM.
foreach(Stats combatant in Combatants){
//Trying to work out how to send them one at a time. Currently using an int.
combatant.SendMessage("Turn");
}
and in the recieving object.
void Turn()
{
StartCoroutine(TurnState());
}
IEnumerator TurnState()
{
selectedTarget.SendMessage("ApplyDamage", attackPower);
BattleManager.battleExecuteTurns++; // this is the int for one at a time.
yield return null;
}
I know my logic might be a bit iffy, not the best programmer but I am crashing my way through it. Using Coroutines so once I through animation in there. Its all ready. Currently just getting a primitive scene together to test the programming.
and what exactly is it that your trying to do? i understand nothing :D
Turn based RPG que logic to execute turns. queOrder is a list, i think I might have a solution, writing it out now. But could fail :S
Yeah, thats one way to put it. Ima add more code in to show what ive got. But Its not much.