Hi! I’m making a turn-based RPG and there is this script of the action choices where the char options should be.
My problem is: if the player choose one action, the next one should have the first one as the pre-selected choice in the box, but this is not happening. For example, if the char called “X” selects the third option, which is use potion, the next char, let’s call “Y”, should have the first option as the pre-selected choice, “Attack”, regardless of what happened in the previous turn. Just works when the previous turn comes from an enemy.
Anyway, a - not so - little bit of my codes:
First, I have these states of the battle enumerated by an enum:
//States of the Battle
[HideInInspector]
public enum ActionBoxStates
{
BEGINTURN,
MAIN,
BLOCKED,
INFO
}
[HideInInspector] public static ActionBoxStates currentState;
The “BEGINTURN” state is basically where the choice ‘1’ will be pre-selected. “MAIN” is where the player will navigate through choices, like attack, use skills, use potion, etc.
So, my Update function is like that:
void Update () {
Debug.Log("ActionBox: " + currentState);
//The start point in every new turn
if(currentState == ActionBoxStates.BEGINTURN)
{
currentState = ActionBoxStates.MAIN;
selectedOption = 1;
}
if (BattleManagerScript.BattleStates.PLAYERCHOICE == BattleManagerScript.currentState)
{
if(ActionBoxStates.MAIN == currentState)
{
//SELECT SOMETHING
if (Input.GetKeyDown(KeyCode.Return))
{
if (selectedOption == 1)
{
//I did a lot of stuff here not related to the enum, so I'm cleaning these codes for the question purpose.
currentState = ActionBoxStates.BLOCKED;
BattleManagerScript.currentState = BattleManagerScript.BattleStates.ENDTURNCONFIRMATION;
BattleManagerScript.NextTurn();
}
if (selectedOption == 3)
{
//All the same here =)
currentState = ActionBoxStates.BLOCKED;
BattleManagerScript.currentState = BattleManagerScript.BattleStates.ENDTURNCONFIRMATION;
BattleManagerScript.NextTurn();
}
}
}
//END TURN
if (Input.GetKeyDown(KeyCode.Space))
{
currentState = ActionBoxStates.BLOCKED;
BattleManagerScript.currentState = BattleManagerScript.BattleStates.ENDTURNCONFIRMATION;
confirmationBox.SetActive(true);
}
}
if (ActionBoxStates.BLOCKED == currentState)
{
fade = true;
}
else
{
fade = false;
VerifyMovement();
}
FadePanel(fade);
}
The “BattleManagerScript” is where the turns are organized and it’s “NextTurn” function simple does that:
public static void NextTurn(){
ReOrderList();
NextBattleState();
ActionBoxManagerScript.ResetActions();
TimelineManagerScript.ArrangeTimeline();
}
“Next Battle State” simple organize the BattleManager’s enum by “PLAYERCHOICE” and “ENEMYCHOICE” by their tags. I guess there’s nothing wrong with it, so I won’t post the code here.
The “ResetActions” of my main script here is doing this:
public static void ResetActions()
{
if(BattleManagerScript.BattleStates.PLAYERCHOICE == BattleManagerScript.currentState)
{
currentState = ActionBoxStates.BEGINTURN;
anim.Rebind(); //will put the chosen option's arrow in the first choice
//I'm using the Debug function here and is showing the state BEGINTURN in currentState, so this code is running and the enum state is changing
Debug.Log("Restart turn with the state: " + currentState);
}
else
{
currentState = ActionBoxStates.BLOCKED;
//When it's an enemy turn, the ActionBox will be blocked, and this is also running properly because in enemy's turn the actions are locked.
}
}
Well, if the enum state is changing in ResetActions(), and it absolutely is, why on Update it doesn’t
Debug located in Update clearly shows that it doesn’t change, it’s already in “MAIN” state. Everything occurs as it should when the turn changes from one enemy to a player’s char. The “currentTurn” goes to “BEGINTURN” state like it should when the enemy finishes it’s turn, but when it changes to one char to another char, the problem appears.
PS: I tend to overexplain, sorry for it and for my rusty english, it’ not my mother tongue.