Hello guys, I’m trying to do a turn based game and i found a way to change turn between the players, but i have a problem.
If i try to run this code:
int i = 0;
while (numActors != 0)
{
if (apelare)
{
apelare = false;
Jucator = jucatori[i];
i++;
Controller = Cast<APawnController>(Jucator->GetController());
if (Controller != NULL)
{
Controller->SetTura_Mea(true);
()->GetTimerManager().SetTimer(TurnTimer, this, &ARISKGameModeBase::MinusCounter, 1.0f, true);
}
else
{
AIController = Cast<AAIControllerPawn>(Jucator->GetController());
AIController->SetTura_Mea(true);
()->GetTimerManager().SetTimer(TurnTimer, this, &ARISKGameModeBase::MinusCounter, 1.0f, true);
}
if (i == numActors)
{
i = 0;
}
}
}
void ARISKGameModeBase::MinusCounter()
{
Counter--;
if (Counter == 0)
{
apelare = true;
Counter = 10;
GetWorldTimerManager().ClearTimer(TurnTimer);
AIController = Cast<AAIControllerPawn>(Jucator->GetController());
if (AIController != nullptr)
{
AIController->SetTura_Mea(false);
}
else
{
Controller = Cast<APawnController>(Jucator->GetController());
Controller->SetTura_Mea(false);
}
}
}
I’ll explain what i’m trying to do with this:
While there are still ‘players’ in game
If i didnt call the ‘MinusCounter’ function(apelare is true
I make "apelare "false
I pick a player
I see if his controller is playercontroller or aicontroller
After i find his controller i set a bool on that controller so i know it’s his turn
After that i start a timer that is meant to be the turn timer
At the end of the timer i set the bool on false so i know it’s not his turn anymore and i set apelare to true
I pick the next player
Why is this crashing? Any ideas?