Skip to main content
The Road To Making An RPG Is Drenched In Blood And Tears

Cursor Memory

I took a little break for a few days, and now I have to experience the hell of picking up a project again after not working on it for a short time.

I worked on "cursor memory", a system where the game remembers which menu options you selected as you navigate between menus, and keeps track of this even across rounds of combat. For example, if you use a specific skill on one turn, then on the next turn, the cursor will default to the "Skill" menu option. If you select "Skill" again, then in the skills sub-menu, the cursor will default to the skill you selected on the previous turn. If you used the skill on a specific enemy, it will also remember which enemy you selected. This allows you to easily repeat the same action across turns.

Previously, I had a limited form of cursor memory due to how I implemented menus. There is a "menu stack" that keeps track of which menu you are currently navigating, and all of its the parent menus.

Basically, when you enter a sub-menu, the game always remembers which menu you came from using the stack, so that you can go back to a previous menu.

There was also a corresponding "cursor stack" which always moved in tandem with the menu stack. The cursor stack kept track of which option was selected in each menu. So whenever you went back to a previous menu, it would remove the current cursor position at the top of the cursor stack, and restore the cursor position for the previous menu. That was the limited form of cursor memory.

The problem with this method is: What if you enter the skill menu, select the third skill on the list, then back out of the skill menu, and then enter the skill menu again? Well, with the previous method, the second time you enter the skill menu, it would revert to having the cursor at the first option on the list. The cursor memory only worked when going "backwards" to a previous menu, not "forwards". The old system also forgot everything between rounds, since the two "stacks" would get reset each round.

In the new cursor memory system, the "menu stack" works the same, but there is no more "cursor stack". Instead, this is how it works.

So going back to the previous example, if you enter the skill menu, then select the third skill, that is recorded in the memory bank. If you back out, that record remains in the memory bank. It doesn't get "removed" like it did in the case of the cursor stack. So when you reopen the skill menu, even if it's in a future round, the cursor position can be retrieved from the memory bank.

The fact that the cursor memory bank is character-specific is important. Otherwise, changing the action you choose for one character would affect the memorized action for another character, and it would be very easy to make mistakes.

The most difficult case of cursor memory, which I might have to change in the future, is cursor memory for combat targets. Because combat targets can disappear.

For example, let's say there are three enemies in combat. Suppose Character A attacks Enemy 3, and Character B attacks and kills Enemy 2. What should cursor memory do next turn?

The current solution is to remember which enemy was selected, rather than which list position was selected, and use the memorized enemy to figure out the correct list position when a target menu comes up. If the memorized enemy isn't found because it died or something, then default to the first enemy in the list.

A small quirk of the system currently is that the "standard attack target" menu and the "skill target" menu are considered the same menu for the purposes of cursor memory. So if you choose the "Fight" option, hover over the third enemy, back out, and then choose the "Skill" option and select a skill, the skill target will default to the third enemy. Thinking about it abstractly, I'm not quite sure whether this behaviour is a problem. I would have to fight a bunch of real battles to see how it feels.

Something I still need to do for later is write code to preserve cursor memory across fights, in addition to across rounds of a single fight. This is useful if you are fighting a lot of enemies and want to just repeat the same series of actions in every fight. This shouldn't be difficult, it's just a matter of saving it in some global variable or something.

I'm shocked I managed to write this much about cursor memory. I thought this would be a tiny post, but it turns out that remembering things is complicated.