It does work, but—as you already guessed—your code is in a loop, showing the same screen over and over again on each SPACE.
Leaving a mission screen via SPACE immediately triggers the
missionScreenOpportunity
event handler. Thus your code is executed again. And because all your conditions are true (you are still docked at a main station, galaxy and system are still the same), the same mission screen is displayed again, ad infinitum.
For this reason you need another condition, for instance in form of a mission variable, which is changed for each screen.
Code: Select all
this.missionScreenOpportunity = function ()
{
if (player.ship.dockedStation.isMainStation)
{
if (galaxyNumber == 5 && system.ID == 202 && !missionVariable.my_mission)
{
mission.runScreen({
titleKey: "spacewreck_title",
messageKey: "spacewreck_start",
model: "anaconda"
});
missionVariable.my_mission = "STAGE_1";
}
}
}
(Note the punctuation as well.)
What does it do? Only if the mission variable
my_mission
(you should give it a better name) doesn't exist, the mission screen is shown, and the mission variable is created and becomes "STAGE_1". Now, when the
missionScreenOpportunity
handler triggers for the next time, the second condition becomes false, because
my_mission
now exists. Result: the screen is shown only once.
For your second mission screen you'll need the additional condition
&& missionVariables.my_mission == "STAGE_1"
, and after calling the screen you'll need to set it to some other value, for instance
missionVariable.my_mission = "STAGE_2"
.
This way you (a) make sure that each screen can only be called once, and (b) leave a trace about the development of your mission in the player's save file, so it is always known at which stage of the mission he currently is.