How to Implement a Player Command Queue?

Hello. Did you play Pre-CU Star Wars Galaxies? I’m not remaking the game, but I did want to make a command queue system like the one you can see in the image below. It’s the window just below the target health bar in the top right of the screenshot. For those that don’t know: “Polearm Spin Attack 1” is the command the player is spamming. It’s being added to the queue each time he presses the button. Each skill takes a certain amount of time to execute. The command currently being executed turns green. When it’s completed, it’s removed from the queue and the next command is executed.

Specifically, what I want to do is rotate a cylinder 30 degrees as a single command. If I wanted to rotate it 90 degrees, I would have to queue the command three times and wait for them to be executed. (The rotation is not instant. I want to use Rinterp).

I’ve been stuck thinking on a solution for this for a few days now. I can usually jerry-rig things like this, but it comes out looking confusing and complicated with no chance of future modification. It’s one of those things that makes me conclude that there must be a better way to do it.

I hope that explains it well enough. If you need more information, then please let me know. I’d really appreciate it if someone can point me in the right direction.

Thank you!

You didn’t say whether you were working in C++ or Blueprint. If the latter, you’ll have to use an array instead of a queue.

You’ll need a way to internally keep track of queuable commands the player has entered. I recommend enums for this.
You’ll also need a way to tell when a command has finished executing. The best way is probably a custom event that you call at the end of all command implementations. In the case of the rotation, you’re probably using the RInterp in combination with a Timeline, so when that finishes, call the event.

In response to your event, check if the command array is currently empty. If not, get and remove the first entry and call the corresponding command function. (If you’re using enums to keep track of commands, you can use a Switch node to do that.)

Now, whenever the player enters a command, you check whether the command array is currently empty. If it is, you execute the command immediately. Otherwise, add the command (mapped to enum) to the array.

I hope this helps. Good luck!