Page 2 of 2

Re: Just a comment on a line of code

Posted: Tue Jan 01, 2013 4:01 pm
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.

Re: Just a comment on a line of code

Posted: Tue Jan 01, 2013 4:47 pm
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"});
    }
}

Re: Just a comment on a line of code

Posted: Wed Jan 02, 2013 8:34 am
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.

Re: Just a comment on a line of code

Posted: Wed Jan 02, 2013 9:15 am
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.)