Action Buttons Disabled At First When Player Turn

There is a limit (I think 400mb). Just the scripts is likely not going to give me the full picture… Should I overwrite the scripts in the project? Trying to figure out how to help on this, but not getting enough of the project may make this impossible. I’ll give it a shot.

That basically blew up the project… since the scripts were technically changed, nothing links up (and there are two scripts the NoteBookManager is erroring on not having…

I’m not sure what’s supposed to go where, and the game is actually unplayable with the new scripts.

Not sure where to go from here…

The scripts are for the latest version and the one that was sent was a very old version so almost nothing would link up. I’ll try and send it piece by piece.

Well, that was most unconventional, but I was able to piece everything together.

What we have going on is a very annoying race condition. I think it didn’t creep into the course project simply out of luck.

So here’s what’s happening: The Turnsystem’s OnTurnChanged is firing, and the UnitActionSystemUI is getting the message BEFORE the Unit is getting it.

That’s why my idea for a fix, to have the UnitActionSystem force a reselect on the selectedUnit wasn’t working, because even that was happening BEFORE Unit was getting the memo, and the Action points aren’t reset until the Unit receives that event. So when the buttons are drawn, since the Unit has no Action Points available, the buttons are disabled.

So I took an unconventional approach…

First, I subscribed to the OnTurnChanged in UnitActionSystem, because this seemed to be the best place for this, and is a one minor script change solution.

The handler then starts a coroutine that simply waits until the next frame before setting the selected Unit.

    private void TurnSystem_OnTurnChanged(object sender, EventArgs e)
    {
        if (TurnSystem.Instance.IsPlayerTurn())
        {
            StartCoroutine(TrickSelectedUnitChange());
        }
    }

    private IEnumerator TrickSelectedUnitChange()
    {
        yield return null;  //allow all events on OnTurnChanged to fire
        SetSelectedUnit(UnitManager.Instance.GetFriendlyUnitList().FirstOrDefault());
    }

At this point, Unit will have reset the Action Points, and UnitActionSystem’s SetSelectedUnit will force a redraw with the correct information.

Kudos on the tutorial explanations before the first time you perform actions, by the way. Nice touch with the notebook paper background, and the instructions were very clear.

1 Like

That worked! You’re a life saver.

Thanks for the compliment! I hope the players like it.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms