When is it my turn? - RPG Turn Order question

While following a Zenva tutorial on how to make a mini-RPG, I have run into a problem regarding when a widget containing user commands should appear and when it should not. Below is what it currently looks like.

Right now, the Attack button is programmed to set the widget with the buttons to Collapsed. Now, when an enemy takes its turn, the widget is not supposed to reappear; it should only appear when it’s the player’s turn again. But the problem is this –

We have this Turn Sequence which helps decide whose turn is next according to their Speed parameter –

(Ignore the Then 0 and Then 1 branches.)

So, I’ve thought about putting in some Boolean or Integer variable that would determine when the button widget should appear and when it shouldn’t, but I’m not sure if that would work or where I could put that. Any suggestions?

Hey @CurleeD85!

I’m not sure where the widget is being spawned/collapsed. Is it in the code you sent?

What I would do is make sure you can differentiate between player characters and enemy characters, then when it is known whose turn it is you check if it is a player character, which will return a bool. Then use a branch, and on True, get the widget back out, and if it is false, bypass that part and continue on.

Hope that helps! :slight_smile:

1 Like

I have been following this Zenva tutorial: https://academy.zenva.com/course/unreal-turn-based-rpg-course/

But, I did some things differently; primarily, creating a separate widget that appears on any camera instead of attaching a widget to the player character.

So far, I have been getting some advice from a user on the UE Discord server. I have put in a Boolean under the parent CharacterBase BP and I intend to use that to determine when it’s a player’s turn and when it’s an enemy character’s turn.

I’m just not sure when to put in a branch that checks whose turn it is. Would it be a good idea to set the Boolean to true at the end of a party member’s false and to true at the end of an enemy’s turn? Though the turn order is based on each participating character’s Speed parameter, instead of player characters acting before enemy characters and vice versa (if that makes any sense).

You put in the check RIGHT BEFORE your code (that you already have) that puts the widget on the screen!

So I have set the PlayerTurn Boolean to True by default and this BP checks if the Boolean is true. If so, then the Battle_UI widget containing four action buttons should appear on the screen.

At the end of the player’s turn, the Boolean is set to False; and at the end of an enemy’s turn, the Boolean is set to True. But the program still behaves oddly; the widget doesn’t always collapse when it’s supposed to.

Hmm. Maybe try “Remove From Parent” instead of “Collapse.”

This ensures that the widget is destroyed, to be created again when needed (very easily). You’re collapsing and re-creating anyway, might as well destroy it. It sounds like you might be creating a stack of collapsed widgets on accident- it could be that it isn’t the same widget at all so the reference is off. Give that a try!

Edit: Also, if “Player Turn” Boolean on Character Base is default to True, and you aren’t changing the value to False for all Enemy characters, it could be that it’s using the default value for ALL Character Base characters.

There is an array variable representing all characters, so maybe I should use a node that extracts info from that. I’ve replaced the “collapse” part with a “Remove from Parent” for the BattleUI widget. But sometimes, it still appears and stacks on top of itself. The program itself is complex, so I can provide a link to a .zip file via PM if you want. Though I don’t expect you to fix anything; just have a look and suggest what I can do to fix the problem myself.

you’re calling a BeginTurn function, its also a good idea to have an EndTurn function. In those you should have an event dispatcher which returns your bool.
Then your widget and other things can bind to that event, this allows you to add other functionality easy, like highlighting the character when its active.

I have an EndTurn function, actually.

cool so with your original question it makes sense for the widget to appear on beginturn and get removed on endturn.

The problem is that the widget doesn’t always disappear when it’s supposed to and that it sometimes stacks on top of itself.

well in the code above your not actually removing it, and in terms of duplication when spawning you can check if it already exists will BattleUI->IsValid(), that assumes the variable is in the same place.

but of course that shouldnt be needed if you remove it properly.

So you’re saying that I should throw in a branch to check whether or not, say, the widget is visible or is valid?

that’ll stop duplicates, but isnt really the issue.

you’ve got 2 choices,

  1. add/remove the widget as needed
  2. reuse the widget, which means check if its valid and update it instead of constructing a new one.

the issue right now ‘seems’ like your just not removing the widget on EndTurn?

Actually, there’s this, too.

I have two parts of the BP on the Game Mode for the project. This first part has a sequence to help determine whose turn it is, based on each participating character’s Speed.

(Ignore the string prints.)

All characters are on an array variable, since the Speed of each character determines who goes next, rather than the player’s side then the enemy’s side.

Have you had a chance to look at the two BP links? Or Mind-Brain?

whats the question though? is the speed order not correct? did you fix the widget?

(post deleted by author)

Right now, the BattleUI widget’s Attack button - as opposed to three others which are not yet programmed - is set to make the widget disappear and end a party member’s turn. I don’t know how to make it any clearer: I’m trying to set the program so that the widget disappears every time the player finishes a turn, stays off the screen when an enemy acts and comes back on only when it’s a party member’s turn. The links I shared determine the turn order based on the Speed (which is the initiative).

sure but turn order doesnt have anything to do with the widget.

so i said previously a good place to do it is in your EndTurn function, show us that.
alternatively since you mentioned it you could do it when a button is pressed (ie Attack button → run logic → remove from parent)