eg:
Code: Select all
var i = 1; // Number
var j = "1"; // String
var k = i + j; // "11" -> probably what wasn't expected.
To work around this, always use parseInt() when working with variables whose type you're not 100% sure of:
Code: Select all
var k = parseInt(i) + parseInt(j); // 2 -> probably what was expected.
This was the underlying reason for an odd bug whereby scooping sometimes filled my cargohold from a single barrel. The culprit was the new player.ship.manifest object and the way cargo is awarded using it.
eg:
Code: Select all
player.ship.manifest["food"] += 1; // Award 1 ton of Food
Code: Select all
var quantity = <something>;
player.consoleMessage(quantity + "<some string>");
player.ship.manifest["food"] += quantity; // WARNING
Code: Select all
player.ship.manifest["food"] += parseInt(quantity); // Ok