Next possible deprecation question: this.ship.etc

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

Next possible deprecation question: this.ship.etc

Post by Lestradae »

The following .js script is giving me complaints in the "1.74" trunk log:

Code: Select all

this.shipDied = this.detonate = function()
{
        if(this.ship.target)
        {
                if(this.ship.target.energy < 125)
                {
                        if(this.ship.owner) this.owner=this.ship.owner;
                        if(this.ship.target.bounty && this.owner.isPlayer)
                        {
                                player.consoleMessage("Bounty : "+this.ship.target.bounty+" cr.");
                                player.consoleMessage("Total : "+Math.round(player.credits*10)/10+" cr.");
                                player.credits += this.ship.target.bounty;
                                player.score++;
                        }
                        this.ship.target.explode();
                }
                else this.ship.target.energy -= 125;
                // can't kill a ship by just setting energy low.
        }
        delete this.shipDied; // make sure it only triggers once.
}
It says this:
JavaScript warning ("nukeSubmunition" 1.0): reference to undefined property this.owner
[script.javaScript.warning.undefinedProp]
... line 16.

Thankful for help

L
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

Those aren't depreciations, they're genuine warnings that something is undefined, in this case this.owner. It may be that in 1.74 the script isn't operating as it should, or something trunk-side is broken so stopping part of it working.

As the dev's always say, trunk is not for playing and is not stable, hence "debugging" scripts in it often isn't worthwhile, as the problem often isn't in the script.
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

..

Post by Lestradae »

Thargoid wrote:
As the dev's always say, trunk is not for playing and is not stable, hence "debugging" scripts in it often isn't worthwhile, as the problem often isn't in the script.
Yeah, I know and agree, concerning my regular game.

I am testing the OSE WiP under trunk, though, as I have this nagging suspicion that 1.74 will not take 3/4 of a year this time to be released and I want to be up to date about what I probably have to take into account concerning OSE.

I will leave the script as it is for the moment then.

8)

L
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Well, I can see a potential problem here:

Code: Select all

          if(this.ship.owner) this.owner=this.ship.owner;
          if(this.ship.target.bounty && this.owner.isPlayer) 

the first line is ok, but the second this.owner is not guaranteed to actually exist.

Change those two lines to

Code: Select all

 if(this.ship.target.bounty && this.ship.owner && this.ship.owner.isPlayer)
and see if the problem persists.

One thing that has changed in trunk is that we now have the full range of js error codes, so 1.74 should notice stuff that 1.73 & before might just have missed.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Kaks wrote:
One thing that has changed in trunk is that we now have the full range of js error codes, so 1.74 should notice stuff that 1.73 & before might just have missed.
Really? That’s news to me. :-)

(If you’re referring to javascript-errors.plist, that’s in 1.73 too, but it’s just there to replace numerical error IDs in log message keys – i.e. it says script.javaScript.warning.undefinedProp instead of script.javaScript.warning.162. SpiderMonkey’s been in strict mode since 1.69, which includes testing for that particular error.)
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Ahruman wrote:
(If you’re referring to javascript-errors.plist, that’s in 1.73 too, but it’s just there to replace numerical error IDs in log message keys – i.e. it says script.javaScript.warning.undefinedProp instead of script.javaScript.warning.162. SpiderMonkey’s been in strict mode since 1.69, which includes testing for that particular error.)
I was referring to that, happy to be corrected! :)

L, you might have had this problem all the time, but only noticed it just now... this can and does happen to a lot of us!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Kaks wrote:
Change those two lines to

Code: Select all

 if(this.ship.target.bounty && this.ship.owner && this.ship.owner.isPlayer)
and see if the problem persists.
That should fix it when only using 1.73+. I not realised that when the missile explodes, the owner could already have died.

I wrote that code before I had 1.73. So the code was written for 1.72 (with a fix for the owner bug in submunition). With your change it won't work correctly in 1.72 anymore. But that can not be seen with this part of the script alone. (When used with 1.72, this.owner is set by the mother-script that spawned the sub-munition)
Post Reply