What exactly do you mean by a map? Can you show it in code?
It'd be helpful to see what menu items are being switched between and what the GUI looks like but if you just got this from reddit that's probably not an option.
I'm gonna use a more simple example (mainly just because I thought he was doing this from the start.) Let's say this is a standard phone grid:
Let's say this is what mald's trying to simulate moving through. What's the best way to do it?
Generally, the smartest thing to do is get coordinates, like a little grid. First, you put in an identifier for each row or column.
I'm using upper case and lower case letters, but this would normally be done with numbers. Because this is based on a phone grid, let's just use letters for now.
using this, you can see any number's location as a combination of coordinates; the x coordinates a, b, and c, and the Y coordinates A, B, C, and D.
This means that we can find the number 1 at (a, A), the number 6 at (c, B), the number 0 at (b, D) and so on. You're probably already seeing how this can be called a 'map'.
The nice thing about this is that it plays really well with arrow keys. for example, the difference between 1 and 2, 4 and 5, and 7 and 8 is the same - where the first number has an X value of a, the second has an x value of b. Likewise, the third column has an x value of c.
This means that if we want to move the cursor right, what we need to do is replace the current x value with the next letter, and that will work
no matter where we are on the grid. All we have to decide is what happens when we're at the far right; not let the cursor move, loop back to the left side, or invade poland.
Likewise, this code is basically the same for moving left, except that it's the previous letter rather than the next one. And the same logic can be done with the y coordinates up and down as well.
Which means that with a bit of clever coding, we can actually make one piece of code that can do all four directions, and then feed it specific values. To use some very slapdash pseudocode:
Code:
function moveCursor(increment, coordinateXorY, cursorValue)
if cursorValue + increment a valid number in (coordinateXorY)
then cursorValue = cursorValue+increment
else if increment is positive
then set cursorvalue to min(coordinateXorY)
else set cursorvalue to max(coordinateXorY)
functionMoveRight()
call function moveCursor(1, "coordinate X", cursorX)
functionMoveLeft()
call function moveCursor(-1, "coordinate X", cursorX)
functionMoveDown()
call function moveCursor(1, "coordinate Y", cursorY)
functionMoveUp()
call function moveCursor(-1, "coordinate Y", cursorY)
In plain english, all this translates to
"When you ask me to move the cursor, you'll give me a direction of forwards or backwards, a coordinate list, and a cursor value. I will move that cursor value to the next valid position in that coordinate list, or wrap around to the start if we're at an end already.
"Then, when you tell me to move Right, Left, Up or Down, I understand that that's a shorthand for a particular direction you want to move the cursor along a particular coordinate".
What Mald has done, instead, is cover EVERY INDIVIDUAL CASE as their own case.
What this means is that mold's code translates to:
"When you ask me to move right;
If I am at 1, move to 2
If I am at 2, move to 3
If I am at 3, move to 1
If I am at 4, move to 5
If I am at 5, move to 6
If I am at 6, move to 4
If I am at 7, move to 8
If I am at 8, move to 9
If I am at 9, move to 7
If I am at 0, move to 0.
When you ask me to move left:
If I am at 1, move to 3
If I am at 2, move to 1
If I am at 3, move to 2..."
Which is exactly as god-awful as it sounds.
Edit: Okay, for full clarity, I did screw up. The actual table of numbers mald's created is not a phone pad, it's actually something far more ungodly. Some of these keys must be shaped like tetronimos or something. But the point still stands that this is needlessly pedantic for something that can be done much more simply.