Page 1 of 1

Mission choice returns null

Posted: Tue May 24, 2011 5:03 am
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

Re: Mission choice returns null

Posted: Tue May 24, 2011 7:31 am
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.

Re: Mission choice returns null

Posted: Tue May 24, 2011 11:04 am
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();
	}
};

Re: Mission choice returns null

Posted: Tue May 24, 2011 1:56 pm
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.

Re: Mission choice returns null

Posted: Tue May 24, 2011 2:30 pm
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.

Re: Mission choice returns null

Posted: Tue May 24, 2011 2:54 pm
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();
	}
};

Re: Mission choice returns null

Posted: Tue May 24, 2011 2:56 pm
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?

Re: Mission choice returns null

Posted: Tue May 24, 2011 3:08 pm
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.

Re: Mission choice returns null

Posted: Tue May 24, 2011 3:09 pm
by Smivs
Am I being dim...how will you collect 750TC cargo if you can't dock?

Re: Mission choice returns null

Posted: Tue May 24, 2011 3:24 pm
by maik
Hmm, maybe by scooping?

Re: Mission choice returns null

Posted: Tue May 24, 2011 3:43 pm
by Smivs
That should make for an interesting 'race'!

Re: Mission choice returns null

Posted: Sun May 29, 2011 12:00 pm
by galpet
maik wrote:
Hmm, maybe by scooping?
You will need to dust off, and calibrate, your mining laser.

Re: Mission choice returns null

Posted: Tue May 31, 2011 1:55 pm
by galpet
I have finished the OXP for the challenge you can see details at RELEASE Oolite RunnerG5 Challenge oxp