Well, the script is far from finished, but here's the context so far. ActiveMenu is set as 6 when player calls save menu (I haven't yet decided how player should do this. Probably from main menu or by pressing E near save point):
if ActiveMenu == 6 then
-- Initiate the active command
NumCommands[ActiveMenu] = NUM_SLOTS
Command(e)
-- Top panel text
TextCenterOnX(50,5,TextSize,"Save Game")
-- Draw the main panel
Panel(25,10,100,90)
-- Draw cursor
Panel(28,15 + 10 * (ActiveCommand[ActiveMenu] - 1),97,25 + 10 * (ActiveCommand[ActiveMenu] - 1))
for i = 1,NUM_SLOTS do
local file = io.open("slot" .. i .. ".dat", "r")
if file == nil then
Text(30,20 + (i - 1) * 10,TextSize,"[empty slot]")
else
Text(30,20 + (i - 1) * 10,TextSize,"Slot " .. i)
end
end
-- Exit menu by pressing Q button
if g_InKey == "q" and GetTimer(e) > BtnTime[e] or g_InKey == "Q" and GetTimer(e)>BtnTime[e] then
BtnTime[e] = GetTimer(e) + 500
ActiveMenu = 1
end
end
The cursor is controlled by Command() which is introduced as a separate function before main().
function Command(e)
-- Initiate the command
if ActiveCommand[ActiveMenu] == nil then
ActiveCommand[ActiveMenu] = 1
end
-- Update menu when player presses up/down
if g_InKey == "w" and GetTimer(e) > BtnTime[e] or g_InKey == "W" and GetTimer(e) > BtnTime[e] then
BtnTime[e] = GetTimer(e) + TIME_W
ActiveCommand[ActiveMenu] = ActiveCommand[ActiveMenu] - 1
end
if g_InKey == "s" and GetTimer(e) > BtnTime[e] or g_InKey == "S" and GetTimer(e) > BtnTime[e] then
BtnTime[e] = GetTimer(e) + TIME_W
ActiveCommand[ActiveMenu] = ActiveCommand[ActiveMenu] + 1
end
-- Set limits for the command - Wrap
if ActiveCommand[ActiveMenu] > NumCommands[ActiveMenu] then
ActiveCommand[ActiveMenu] = 1
end
if ActiveCommand[ActiveMenu] < 1 then
ActiveCommand[ActiveMenu] = NumCommands[ActiveMenu]
end
end
NUM_SLOTS is 7 and TIME_W is 145. I don't think Command() is causing problems because other menus using it are working just fine. "Top panel" is introduced if any of my menus is active (I'm planning to create various menus that work with the same logic, for example inventory and shop.)