Page 1 of 1

How do I stop my mission screen [solved]

Posted: Thu Mar 10, 2011 8:53 pm
by Smivs
I'm doing a little mission thing (my first) and I've got stuck...or at least my mission screen has. Pressing 'Space' doesn't do anything. I think looking around the board it's stuck in a sort of loop, and pressing ' space' is just triggering it again.

Code: Select all

this.missionScreenOpportunity = function ()
{
    if (player.ship.dockedStation.isMainStation) 
	{
		if (galaxyNumber == 5 && system.ID == 202)
		{
			mission.runScreen({
				titleKey: "spacewreck_title",
				messageKey: "spacewreck_start",
				model: "anaconda"
			})
                }
        }
};
How do I make 'Press Space' work, please?

Re: How do I stop my mission screen

Posted: Thu Mar 10, 2011 8:58 pm
by Thargoid

Code: Select all

this.startUp = function()
{
this.missionFlag = "NO";
}

this.missionScreenOpportunity = function ()
{
    if (player.ship.dockedStation.isMainStation) 
	{
		if (galaxyNumber == 5 && system.ID == 202 && this.missionFlag && this.missionFlag === "NO")
		{
			mission.runScreen({
				titleKey: "spacewreck_title",
				messageKey: "spacewreck_start",
				model: "anaconda"
			});
			this.missionFlag = "DONE";
                }
        }
};
Something like the above. Use a flag to denote when the mission has been displayed.

What's happening is that at the end of displaying a mission screen (yours for example) there is then an opportunity for another mission screen to be displayed, so the event triggers again. And as the if statement is still valid in your original case, your mission screen is displayed again. Hence space is working, but as soon as your screen closes it opens again, which is instantaneously hence it appears like space isn't working.

By adding this.missionFlag, you're making the if statement true for the first display, but then by changing the value of the flag, on the second calling the if statement is false and so the display doesn't recur.

Re: How do I stop my mission screen

Posted: Thu Mar 10, 2011 9:03 pm
by Smivs
Thanks Thargoid...I thought it was that but didn't know how to stop it. :roll:

Re: How do I stop my mission screen

Posted: Thu Mar 10, 2011 9:08 pm
by Commander McLane
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.

Re: How do I stop my mission screen

Posted: Fri Mar 11, 2011 8:12 pm
by Smivs
I've tried both the above suggestions now. Thargoid's works and the screen is going on pressing 'space'.
@McLane, I'm afraid I couldn't get yours to work. I c&p'd it and just changed the title and message keys to mine, and the 'my_mission' to 'spacewreck_mission' (you'll have guessed it concerns a spacewreck by now). No mission screen.

Code: Select all

this.missionScreenOpportunity = function ()
{
    if (player.ship.dockedStation.isMainStation) 
   {
      if (galaxyNumber == 5 && system.ID == 41 && !missionVariable.spacewreck_mission)
      {
         mission.runScreen({
            titleKey: "spacewreck_title",
            messageKey: "beanxeat"
         });
         missionVariable.spacewreck_mission = "STAGE_1";
                }
        }
}
Just to complicate things further, I've decided I now want a mission screen at the previous planet visited (Beanxeat) telling you to go the system (Qutius) where the mission occurs. The above is the code for the first of these screens, and it doesn't seem to work as no mission screen appears. There is nothing in the log.

Looking ahead, the entire code (currently not working) is below, to check I understood the points you were making regarding the variables.

Code: Select all

this.missionScreenOpportunity = function ()
{
    if (player.ship.dockedStation.isMainStation) 
   {
      if (galaxyNumber == 5 && system.ID == 41 && !missionVariable.spacewreck_mission)
      {
         mission.runScreen({
            titleKey: "spacewreck_title",
            messageKey: "beanxeat"
         });
         missionVariable.spacewreck_mission = "STAGE_1";
                }
        }
};

this.missionScreenOpportunity = function ()
{
    if (player.ship.dockedStation.isMainStation) 
   {
      if (galaxyNumber == 5 && system.ID == 202 && missionVariable.spacewreck_mission == "STAGE_1")
      {
         mission.runScreen({
            titleKey: "spacewreck_title",
            messageKey: "spacewreck_start",
            model: "spacewreck_anaconda"
         });
         missionVariable.spacewreck_mission = "STAGE_2";
                }
        }
};

this.shipLaunchedFromStation = function() 
{
         if (galaxyNumber == 5 && system.ID == 202)

    {  
    system.addShipsToRoute(this.role1, this.count1, 0.5, "sp");
    system.addShipsToRoute(this.role2, this.count2, 0.5, "sp");
    }
}

All three elements have been tested inasmuch as the actual mission part (ships/asteroids in the right place etc) is working, and both screens work on their own when using Thargoids code. I mention this as it confirms that the problem does not lie elsewhere such as missiontext.plist.

I should also mention that I can't get both working together using Thargoids code, but I expect you need to do more than just reproduce it a second time!

Re: How do I stop my mission screen

Posted: Fri Mar 11, 2011 9:15 pm
by Thargoid
You can't have two instances of a named function in a single script like you have above - the second one will just overwrite the first. That's why you're not getting the previous one appearing - you need to combine the two together into one single function.

McLane's method and mine are essentially the same, except his is superior as the value will be saved to the mission variable between save games, whereas mine will reset. But functionally their operation is the same.

My suggestion would be to take one of my mission OXPs, such as Stealth, Aquatics (the Kraken bit of it) or TCAT and see how missionScreenOpportunity is used there. It's exactly the method that McLane describes, and I hope should get you pointed in the right direction.

Re: How do I stop my mission screen

Posted: Fri Mar 11, 2011 9:34 pm
by Smivs
Thanks, Thargoid, I'll have a look.
Mrs_S knows enough to have told me that might be the problem, but not enough to fix it. :(
It'll give me something to do and something new to learn!

Re: How do I stop my mission screen

Posted: Fri Mar 11, 2011 10:24 pm
by Smivs
Sorted :D
Thanks Thargoid, you pointed me in the right direction and I've managed to sort it out. All seems to be working perfectly.

Re: How do I stop my mission screen

Posted: Fri Mar 11, 2011 10:33 pm
by TGHC
Smivs wrote:
Mrs_S knows enough to have told me that might be the problem, but not enough to fix it.
You just can't get the staff these days can you!

<dives into a foxhole>

Re: How do I stop my mission screen

Posted: Fri Mar 11, 2011 11:35 pm
by Commander McLane
I just now notice that I've made a small but important typo. It should be 'missionVariables'. Without the 's' nothing will be written in the save-file.

Re: How do I stop my mission screen

Posted: Fri Mar 11, 2011 11:41 pm
by Smivs
Thanks, I'd actually spotted that. It's already been corrected.
All working now, so again thanks for the help....as always much appreciated.
Ditto to Thargoid.