diff --git a/devNotes/twine JS.txt b/devNotes/twine JS.txt index d3f6679d3abbbf24ac602538ab75de1fff59164d..3a430026511a0ec063791c7b2ceb8db940cdf769 100644 --- a/devNotes/twine JS.txt +++ b/devNotes/twine JS.txt @@ -2929,7 +2929,8 @@ window.cashX = function(cost, what, who) { const V = State.variables; if(isNaN(cost)){ - V.lastWeeksErrors += (' NaN: \"' + cost + '\"" at ' + what + ','); + V.lastWeeksErrors += `NaN: "${cost}" at ${what}, + `; } else { //INCOME @@ -2940,42 +2941,42 @@ window.cashX = function(cost, what, who) { V.lastWeeksCashIncome[what] += cost; //record the slave, if available - if (who !== undefined){ - if(what == "slaveTransfer"){ - who.slaveCost = cost; - } else { + if (typeof who !== 'undefined'){ who.lastWeeksCashIncome += cost; who.lifetimeCashIncome += cost; - } } //Spend the money V.cash += cost; } else { - V.lastWeeksErrors += (' unknown place \"' + what +'\",'); + V.lastWeeksErrors += `Unknown place "${what}",`; } } //EXPENSES else if(cost < 0) { - if (typeof V.lastWeeksCashExpenses[what] !== 'undefined') { - - //record the action - V.lastWeeksCashExpenses[what] += cost; - - //record the slave, if available - if (who !== undefined){ + if (typeof V.lastWeeksCashExpenses[what] !== 'undefined') { + + //record the action + V.lastWeeksCashExpenses[what] += cost; + + //record the slave, if available + if (typeof who !== 'undefined'){ + if (what === "slaveTransfer"){ + who.slaveCost = cost; + } else { who.lifetimeCashExpenses += cost; } - - //Spend the money - V.cash += cost; - } else { - V.lastWeeksErrors += (' unknown place \"' + what +'\",'); } + + //Spend the money + V.cash += cost; + } else { + V.lastWeeksErrors += `Unknown place "${what}",`; + } } else { - //somebody probably tried to pass a 0, ignore it. + //somebody probably tried to pass a 0, ignore it. New slaves will default to "slaveCost: 0", no need to call a costX for it. } return cost; }