Just a comment on a line of code

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

Moderators: another_commander, winston

User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2289
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Just a comment on a line of code

Post by Wildeblood »

Commander McLane wrote:
Which means that the better way of doing it would be:

Code: Select all

this.missionScreenOpportunity = function()
{
    if (player.ship.isDocked && player.ship.dockedStation.isMainStation)
    {
        mission.runScreen({title: "Automated GalCop Station Greeting", message: "Welcome, Commander"});
    }
}
Nope, the boolean is called just .docked, not .isDocked.
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: Just a comment on a line of code

Post by Commander McLane »

Wildeblood wrote:
Nope, the boolean is called just .docked, not .isDocked.
Darn. Should've double-checked. :oops:

Okay, so:

Code: Select all

this.missionScreenOpportunity = function()
{
    if (player.ship.docked && player.ship.dockedStation.isMainStation)
    {
        mission.runScreen({title: "Automated GalCop Station Greeting", message: "Welcome, Commander"});
    }
}
User avatar
Massively Locked
Dangerous
Dangerous
Posts: 84
Joined: Tue Nov 20, 2012 12:20 pm

Re: Just a comment on a line of code

Post by Massively Locked »

Smivs- "Steep" is an understatement. :) Like you said, it's incredibly frustrating but also wonderfully rewarding when a few simple lines of code finally work. I also can't agree more with what you say about "the good folks around this board". Take Eric's post right below yours- it's excellent advice for any greenhorn coder that you won't find in any JS wiki or FAQ or tutorial.

Tricky-
Tricky wrote:
Also read other OXP scripts for examples on how to handle things.
So true. After trying one thing after another after another and having none of it work, I dove into the scripts of my installed OXPs to see how you guys did it. That was when I got my "Ah Ha!" moments. The wikis are important, but they now seem to me like just a starting point. I think you really need to read other people's working code to fully understand how things are put together.

Cmdr McLane- Thanks for the revised code! When I first briefly read about missionScreenOpportunity in the wiki, I wasn't sure how to integrate it. Do I put it before my 'If' statement? Do I put it after? Is it part of the 'If' statement? I'm definitely going to add and play around with it to understand it more.

As for the second flaw in the code: I'm first thinking that it's got something to do with the parens/braces, but I counted them & they all match up. Next guess- maybe a ";" is missing somewhere? Either after the last brace or the second-to-last brace... Now to the fine print. Damn- not even close!

But you bring up an important point- it's one of the many, many reasons why it took me hours to write a three line script. Here's another one: after I got clued in that player.ship.dockedStation was what I needed, I figured that I can use PS.dockedStation (because 'PS' is the abbreviation that works in the debug console). Needless to say, that wasn't happening.

ps.dockedStation? Nope.

Ps.dockedStation? Try again.

pS.dockedStation? You are wrong, JavaScript-breath!

OK- player.ship.dockedStation it is.
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: Just a comment on a line of code

Post by Eric Walch »

Massively Locked wrote:
....after I got clued in that player.ship.dockedStation was what I needed, I figured that I can use PS.dockedStation (because 'PS' is the abbreviation that works in the debug console). Needless to say, that wasn't happening.
Yep, the abbreviations only work in the console. :lol:


missionScreenOpportunity can be used instead of shipDockedWithStation and will fire immediately after shipDockedWithStation. missionScreenOpportunity is a bit of a special handler that works a bit different than all others. All others fire for all oxps, even if no longer needed. e.g. shipDockedWithStation will continue to be send to all remaining oxps, even when an oxp forced a launch inside this handler. Therefor it is still needed to check if you are still docked.

missionScreenOpportunity is one that only fires for one oxp at a time. Only when that oxp does not use it for a mission screen, the handler is send to the next oxp. When it is used by an oxp, it stops sending it to further oxps. And also important: When the mission screen of an oxp is finished showing, the oxp that showed the missionscreen is the first that is offered a new opportunity. That way you can create multiple screen messages without the risk of another oxp adding its own screen in between. (And because a missionScreenOpportunity is only send to docked players, there is no need to do any checking for being docked.)
Post Reply