mn.unloadMission doesn't seem to work. Pertinent Lua code is:
--Load the mission
if not load_mission then
mn.unloadMission()
load_mission_success = mn.loadMission("MenuScene-01.fs2")
load_mission = 1
end
--Make sure we actually loaded the mission
if load_mission_success then
mn.simulateFrame()
mn.renderFrame()
end
--Function to handle a section every frame
section = function(name, event, num)
--Setup color and margin for this resolution
margin = gr.getScreenHeight()/6
gr.setColor(0, 255, 0)
--Get corner coordinates for this box
x1 = gr.getScreenWidth()-180
y1 = margin*num+20
x2 = gr.getScreenWidth()-21
y2 = margin*num+55
--When the mouse is OVER this section...
if ms.getX() > x1 and ms.getX() < x2 and ms.getY() > y1 and ms.getY() < y2 then
--Draw the dark green insides
gr.setColor(0, 96, 0)
gr.drawRectangle(x1, y1, x2, y2, true, false)
--Draw the little target lines now
gr.setColor(0, 255, 0)
x = x1+(x2-x1)/2
y = margin*num
--Top target line
gr.drawLine(x, y, x, y+15)
--Bottom target line
y = margin*num+65
gr.drawLine(x, y, x, y+15)
--Left target line
x = gr.getScreenWidth()-200
y = margin*num+40
gr.drawLine(x, y, x+15, y)
--Right target line
x = gr.getScreenWidth()-16
gr.drawLine(x, y, x+15, y)
--Handle the button click
if ms.isButtonDown("Left") then
bs.setEvent(event)
gr.drawRectangle(x1, y1, x2, y2, false, false)
sd.playInterfaceSound("user_c.wav")
load_mission = 0
end
end
--Draw the outline
gr.drawRectangle(x1, y1, x2, y2, false, false)
--Color should always be pure green, so I'll skip setting the color for the name
gr.drawString(name, x1 + ( (x2-x1) - gr.getTextWidth(name) ) / 2, margin*num+35, false)
end
section("Ready Room", "GS_EVENT_NEW_CAMPAIGN", 0)
section("Campaign Room", "GS_EVENT_CAMPAIGN_ROOM", 1)
section("Tech Room", "GS_EVENT_TECH_MENU", 2)
section("Barracks", "GS_EVENT_BARRACKS_MENU", 3)
section("Options", "GS_EVENT_OPTIONS_MENU", 4)
section("Exit", "GS_EVENT_QUIT_GAME", 5)
If you play a mission and then leave it somehow, going back to the main menu, you will still be "in that mission". I tried to fix this by making the intro level reload upon leaving the main menu. Setting load_mission=0 upon entering a different section (e.g. Techroom) caused FS2 to crash upon returning; therefore, I then tried to add an unloadMission before the loadMission thinking that the problem was that I had a loadMission statement with a mission already loaded. Then I got the error:
LUA ERROR: [string "GS_STATE_MAIN_MENU"]:3: attempt to call field `unloadMission' (a nil value)
------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------
Using a new reload_mission flag to cause unloadMission to fire only on returning to the main hall, and not on first startup (before the mission's loaded), did not resolve the problem.