Mission choice returns null

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

Moderators: winston, another_commander

Post Reply
galpet
Above Average
Above Average
Posts: 23
Joined: Thu May 19, 2011 11:36 am
Location: Australia

Mission choice returns null

Post by galpet »

I'm trying to put together an oxp for the Oolite Runner Challenge discussed in https://bb.oolite.space/viewtopic.php?f=2&t=9880. This is my first attempt at JavaScript, so, I'm not well versed in these dark arts, and need some help. The problem is I can't get the "choice" from the mission screen, it always returns null.

System is Linux SUSE 11.3 and I'm using Oolite 1.75.2

What I want is:
"First mission screen" with "Incoming Message." option
Choosing "Incoming Message." should load "Second mission screen." with "Immediate Launch." option.
but the choice returned is null.

My missiontext.plist looks like:

Code: Select all

{
    // Oolite RunnerG5 Mission
    "runnerG5_title"   = "Oolite Runner Mission";
    "runnerG5_Start_1" = "First mission screen.";
    "runnerG5_Start_2" = "Second mission screen.";
    "runnerG5_End_1"   = "Success mission screen.";
    "runnerG5_Fail_1"  = "Failed mission screen.";
    "runnerG5_Start_1_opt" =
    {
        "MESSAGE" = "Incoming Message.";
    };
    "runnerG5_Start_2_opt" =
    {
        "LAUNCH" = "Immediate Launch.";
    };
    "runnerG5_End_1_opt" =
    {
        "SUCCESS" = "Success.";
    };
    "runnerG5_Fail_1_opt" =
    {
        "FAIL" = "Failed.";
    };
}
My missions look like:

Code: Select all

this.missionStart = function ()
{
	mission.runScreen(
	{
		titleKey: "runnerG5_title",
		messageKey: "runnerG5_Start_1",
		choicesKey: "runnerG5_Start_1_opt"
	}, runnerG5Callback);
};

this.missionEnd = function()
{
	mission.runScreen(
	{
		titleKey: "runnerG5_title",
		messageKey: "runnerG5_End_1",
		choicesKey: "runnerG5_End_1_opt"
	}, runnerG5Callback);
};

this.missionFail = function()
{
	mission.runScreen(
	{
		titleKey: "runnerG5_title",
		messageKey: "runnerG5_Fail_1",
		choicesKey: "runnerG5_Fail_1_opt"
	}, runnerG5Callback);
};
And my callback function looks like

Code: Select all

this.runnerG5Callback = function (choice)
{
	log(this.name+".runnerG5Callback", "called");
	log(this.name+".runnerG5Callback.choice", choice);
	switch(choice)
	{
		case "MESSAGE":
			mission.runScreen(
			{
				titleKey: "runnerG5_title",
				messageKey: "runnerG5_Start_2",
				choicesKey: "runnerG5_Start_2_opt"
			}, runnerG5Callback);
			break;
		case "LAUNCH":
			player.ship.launch();
			break;
		case "SUCCESS":
			// Do Success
			break;
		case "FAIL":
			// Do Fail
			break;
		case null:
			player.consoleMessage("NULL AGAIN", 10);
			break;
	}
};
Any help would be greatly appreciated.

Thanks
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: Mission choice returns null

Post by Commander McLane »

It's working here.

Here's the log excerpt:

Code: Select all

09:27:02.710 [McLane-testscript.runnerG5Callback]: called
09:27:02.711 [McLane-testscript.runnerG5Callback.choice]: MESSAGE
09:27:06.630 [McLane-testscript.runnerG5Callback]: called
09:27:06.630 [McLane-testscript.runnerG5Callback.choice]: LAUNCH
After that I got launched.

When and how do you call this.missionStart?

I copied and pasted your code into my test script and added

Code: Select all

/* event handlers */

this.missionScreenOpportunity = function()
{
    this.missionStart();
}
in order to call the first mission screen.
galpet
Above Average
Above Average
Posts: 23
Joined: Thu May 19, 2011 11:36 am
Location: Australia

Re: Mission choice returns null

Post by galpet »

Thank for the reply. It's nice to know that some of my code is correct.

I want the mission screens to display when the saved game is loaded, so I run it from guiScreenChanged

Code: Select all

this.guiScreenChanged = function ()
{
	if (guiScreen === "GUI_SCREEN_MISSION" ||
			guiScreen === "GUI_SCREEN_REPORT" ||
			!player.ship.docked)
	{
		return;
	}
	if (player.ship.dockedStation.isMainStation &&
			galaxyNumber === 4 &&
			system.ID === 96 &&
			player.name === "RunnerG5"  &&
			runnerG5Start === false)
	{
		player.ship.removeAllCargo();
		player.score = 0;
		player.credits = 0;
		this.missionStart();
	}
	else if (player.ship.dockedStation.isMainStation &&
			galaxyNumber === 4 &&
			system.ID === 33 &&
			player.name === "RunnerG5"  &&
			runnerG5Success > 0)
	{
		this.missionEnd();
	}
	else
	{
		this.missionFail();
	}
};
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Mission choice returns null

Post by Eric Walch »

galpet wrote:
I want the mission screens to display when the saved game is loaded, so I run it from guiScreenChanged
The this.missionScreenOpportunity() also fires after loading a saved game so no need to use a less conventional method. And when you only want it to run on loading a saved game, you can delete the handler from within the handler, so that is won't fire a second time.
galpet
Above Average
Above Average
Posts: 23
Joined: Thu May 19, 2011 11:36 am
Location: Australia

Re: Mission choice returns null

Post by galpet »

Eric Walch wrote:
The this.missionScreenOpportunity() also fires after loading a saved game so no need to use a less conventional method. And when you only want it to run on loading a saved game, you can delete the handler from within the handler, so that is won't fire a second time.
Thanks for the advice, but this is my first venture into JavaScript, and I have no idea what this means, or how to do what you suggest.
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: Mission choice returns null

Post by Commander McLane »

It means that you replace the guiScreenChanged event handler with the missionScreenOpportunity event handler. This has the additional advantage that you don't need to bother with checking that you're not on GUI_SCREEN_MISSION or GUI_SCREEN_REPORT, because the missionScreenOpportunity handler does that all by itself.

Code: Select all

this.missionScreenOpportunity = function ()
{
	if (!player.ship.docked)
	{
		return;
	}
	if (player.ship.dockedStation.isMainStation &&
			galaxyNumber === 4 &&
			system.ID === 96 &&
			player.name === "RunnerG5"  &&
			runnerG5Start === false)
	{
		player.ship.removeAllCargo();
		player.score = 0;
		player.credits = 0;
		this.missionStart();
	}
	else if (player.ship.dockedStation.isMainStation &&
			galaxyNumber === 4 &&
			system.ID === 33 &&
			player.name === "RunnerG5"  &&
			runnerG5Success > 0)
	{
		this.missionEnd();
	}
	else
	{
		this.missionFail();
	}
};
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: Mission choice returns null

Post by Commander McLane »

By the way: your code means that the player is not allowed to dock anywhere between start and finish. Is that intentional?
galpet
Above Average
Above Average
Posts: 23
Joined: Thu May 19, 2011 11:36 am
Location: Australia

Re: Mission choice returns null

Post by galpet »

Thanks for clearing that up for me. I will give it a go tomorrow.
Commander McLane wrote:
By the way: your code means that the player is not allowed to dock anywhere between start and finish. Is that intentional?
Correct. That's the idea of the challenge. Doing a 50light year non-stop run, collecting 750t cargo and 100 kills on the way. Plus the added excitement of everyone trying to stop you.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Mission choice returns null

Post by Smivs »

Am I being dim...how will you collect 750TC cargo if you can't dock?
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
maik
Wiki Wizard
Wiki Wizard
Posts: 2028
Joined: Wed Mar 10, 2010 12:30 pm
Location: Ljubljana, Slovenia (mainly industrial, feudal, TL12)

Re: Mission choice returns null

Post by maik »

Hmm, maybe by scooping?
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Mission choice returns null

Post by Smivs »

That should make for an interesting 'race'!
Commander Smivs, the friendliest Gourd this side of Riedquat.
galpet
Above Average
Above Average
Posts: 23
Joined: Thu May 19, 2011 11:36 am
Location: Australia

Re: Mission choice returns null

Post by galpet »

maik wrote:
Hmm, maybe by scooping?
You will need to dust off, and calibrate, your mining laser.
galpet
Above Average
Above Average
Posts: 23
Joined: Thu May 19, 2011 11:36 am
Location: Australia

Re: Mission choice returns null

Post by galpet »

I have finished the OXP for the challenge you can see details at RELEASE Oolite RunnerG5 Challenge oxp
Post Reply