current output:
created card: Card {}
and because of that, this fails:
TypeError: Cannot read properties of undefined (reading '0')
My call function for creating a card:
function Prepare_units(Player) { // Player contains example data cards.
var UnitHolder = [];
Player.forEach(function (MinionUnit) {
var CreatedCard = new Card.Card(MinionUnit);
console.log("created card:",CreatedCard);
CreatedCard.attack = CreatedCard.value[0];
CreatedCard.health = CreatedCard.value[1];
UnitHolder.push(CreatedCard);
});
return UnitHolder;
}
CardsData holds a promise (database call and return of spesific card)
call function in my Cards Class:
constructor(MinionId) {
this.CardsData(MinionId).then(data => {
if (data) {
this.card = data;
console.log("collected data",data);
this.attack = this.card.CardValue(0);
this.health = this.card.CardValue(1);
this.alive = true;
this.deathrattle = this.card.deathrattle;
return this;
} else {
console.log("error calling constructior, local set",data);
this.Instance = "LOCAL";
return this;
}
} );
}
exports:
module.exports = {
CardCreator : CardCreator,
Card: Card,
}
Shouldnt i be able to call this.attack or createdCard.value from the Prepare_units method?
expected result is to get values from the card Class after creating a new instance.
Edit: I know why the properties are undefined. because it cant read it, but i dont know how to proceed to fix it.