Strict mode warnings

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

Moderators: another_commander, winston, Getafix

Post Reply
User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Strict mode warnings

Post by Milo »

Code: Select all

Warning (strict mode): reference to undefined property ship.missiles[i].primaryRole
    Active script: oolite-populator 1.89
    oolite-populator.js, line 2306:
    			if (ship.missiles[i].primaryRole == "EQ_MISSILE" && chance < Math.random())
I haven't looked into this one.

Code: Select all

Warning (strict mode): reference to undefined property market[commodity].marketMaskPrice
    Active script: Oolite Trader AI 1.89
    oolite-priorityai.js, line 2543:
    				var adjust = market[commodity].marketEcoAdjustPrice * multiplier * quantity / market[commodity].marketMaskPrice;

Warning (strict mode): reference to undefined property market[commodity].marketEcoAdjustPrice
    Active script: Oolite Trader AI 1.89
    oolite-priorityai.js, line 2543:
    				var adjust = market[commodity].marketEcoAdjustPrice * multiplier * quantity / market[commodity].marketMaskPrice;
For the market warnings, I at first thought of an unknown commodity name (which would also be a problem here), but when I scanned in-system ships I found no commodities in their cargoList that didn't have an entry at the main station. However, none of the system.mainStation.market entries had a marketEcoAdjustPrice or marketMaskPrice property.

I think it could be fixed by enclosing lines 2543 and 2544 in an if block like this:

Code: Select all

				if (market[commodity].marketEcoAdjustPrice && market[commodity].marketMaskPrice) // defined and non-zero (for division)
				{
					var adjust = market[commodity].marketEcoAdjustPrice * multiplier * quantity / market[commodity].marketMaskPrice;
					profit += adjust;
				}
Next warning:

Code: Select all

Warning (strict mode): reference to undefined property this.__ltcache.oolite_homeStation
    Active script: YAH patrol AI 4.5.1
    oolite-priorityai.js, line 903:
    	if (this.__ltcache.oolite_homeStation === null)
Suggested revision beginning at line 901 of oolite-priorityai.js:

Code: Select all

PriorityAIController.prototype.homeStation = function() 
{
	if (this.__ltcache.oolite_homeStation !== undefined)
	{
		if (this.__ltcache.oolite_homeStation === null)
		{
			return null;
		}
		if (this.__ltcache.oolite_homeStation.isValid)
		{
			return this.__ltcache.oolite_homeStation;
		}
	}
	// home station has not been assigned yet (property undefined)
	// home station might be the owner of the ship, or might just
	// be a group member
	if (this.ship.owner && this.ship.owner.isStation && this.friendlyStation(this.ship.owner))
	{
		this.__ltcache.oolite_homeStation = this.ship.owner;
		return this.ship.owner;
	}
	if (this.ship.group)
	{
		var gs = this.ship.group.ships;
		for (var i = gs.length-1 ; i >= 0  ; i--)
		{
			if (gs[i] != this.ship && gs[i].isStation && this.friendlyStation(gs[i]))
			{
				this.__ltcache.oolite_homeStation = gs[i];
				return gs[i];
			}
		}
	}
	this.__ltcache.oolite_homeStation = null;
	return null;
}
Next pair of warnings (note, my line numbers may be slightly different due to changes mentioned above):

Code: Select all

Warning (strict mode): reference to undefined property this.ship.group.leader.AIScript.oolite_intership.cargodemanded
    Active script: Oolite Pirate AI 1.89
    oolite-priorityai.js, line 2039:
    			if (this.ship.group.leader && this.ship.group.leader.AIScript.oolite_intership && this.ship.group.leader.AIScript.oolite_intership.cargodemanded > 0)

Warning (strict mode): reference to undefined property this.ship.group.ships[0].AIScript.oolite_intership.cargodemanded
    Active script: Oolite Pirate AI 1.89
    oolite-priorityai.js, line 2048:
    			else if (this.ship.group.ships[0].AIScript.oolite_intership && this.ship.group.ships[0].AIScript.oolite_intership.cargodemanded > 0)
One way to "fix" this (the code works, but strict mode dislikes it) without too much added code is to provide a default value for the comparison, like this:

if (this.ship.group.leader && this.ship.group.leader.AIScript.oolite_intership && (this.ship.group.leader.AIScript.oolite_intership.cargodemanded || 0) > 0)

With this, if this.ship.group.leader.AIScript.oolite_intership.cargodemanded is undefined, the || 0 replaces it with zero. The result of 0 > 0 is false. undefined > 0 also is false, but also triggers a warning.

Post Reply