I am trying to get a create a variable oldPlayerStats
to get the current value of G.playerStats
, so that later when G.playerStats
gets updated, I can subtract the oldPlayerStats
from the new value of G.playerStats
to get the difference.
However for some reason, oldPlayerStats
updates to always match G.playerStats
.
Relevant code below:
const oldPlayerStats = G.playerStats;
console.log(oldPlayerStats[0].wood); //Is 10 as it should be
//This function affects the value of `G.playerStats`. It does not do anything to oldPlayerStats
cardFunction.function(G, ctx, ctx.currentPlayer, G.opponent, G.attackMultiplier);
console.log(oldPlayerStats[0].wood); //Should be 10, but instead updates to match the new value of `G.playerStats`