How do I stop my mission screen [solved]

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

How do I stop my mission screen [solved]

Post 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?
Last edited by Smivs on Mon Mar 14, 2011 3:56 pm, edited 1 time in total.
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: How do I stop my mission screen

Post 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.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: How do I stop my mission screen

Post by Smivs »

Thanks Thargoid...I thought it was that but didn't know how to stop it. :roll:
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: How do I stop my mission screen

Post 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.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: How do I stop my mission screen

Post 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!
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: How do I stop my mission screen

Post 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.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: How do I stop my mission screen

Post 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!
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: How do I stop my mission screen

Post 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.
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
TGHC
---- E L I T E ----
---- E L I T E ----
Posts: 2157
Joined: Mon Jan 31, 2005 4:16 pm
Location: Berkshire, UK

Re: How do I stop my mission screen

Post 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>
The Grey Haired Commander has spoken!
OK so I'm a PC user - "you know whats scary? Out of billions of sperm I was the fastest"
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: How do I stop my mission screen

Post 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.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: How do I stop my mission screen

Post 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.
Commander Smivs, the friendliest Gourd this side of Riedquat.
Post Reply