You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Giving this little engine a go for a little hobby project. Attempting to create a "harvestable" item class to be used by the players. I have created a property to the following:
function harvest({ player, dobj, iobj, verbstr, argstr, dobjstr, prepstr, iobjstr }) {
if (dobjstr) {
player.tell(`Parsed ${dobjstr} from string.`);
for (let item of this.harvestItems) {
if (item.matchers.indexOf(dobjstr) > -1) {
if (item.amount > 0) {
item.amount = item.amount -1;
player.tell(`You take some ${dobjstr} from the ${this.name}`)
player.tell(`There is now ${item.amount} left`)
// not including all insertion / cloning logic here for clarity
return;
}
break;
}
}
player.tell(`There is no harvestable ${dobjstr} here`)
} else {
player.tell(`Harvest what from ${this.name}?`);
}
}
but every time I make an update to the "amount" value, the changes are discarded as soon as the script finishes - as if the state is not being saved. I see that the value gets outputted as 0 remaining, but running the script again results in the same display of 0, running through the same branches again. Am I doing something wrong, or is this type of functionality not supported out of the box?
The text was updated successfully, but these errors were encountered:
I think the value change is not saved because it's in a nested object and the main object saving logic doesn't do a deep check. The workaround is to re-assign the toplevel object property which is being changed, as shown below (marked "HERE"). In other terms, work with an object reference in your loop, and reassign the this.harvestItems property.
functionharvest({ player, dobj, iobj, verbstr, argstr, dobjstr, prepstr, iobjstr }){if(dobjstr){player.tell(`Parsed ${dobjstr} from string.`);letharvests=this.haverstItems// HERE...for(letitemofharvests){if(item.matchers.indexOf(dobjstr)>-1){if(item.amount>0){item.amount=item.amount-1;player.tell(`You take some ${dobjstr} from the ${this.name}`)player.tell(`There is now ${item.amount} left`)this.harvestItems=harvests// AND HERE...// not including all insertion / cloning logic here for clarityreturn;}break;}}player.tell(`There is no harvestable ${dobjstr} here`)}else{player.tell(`Harvest what from ${this.name}?`);}}
I just did that with a code very similar to yours, and it worked for me. For the record, in the demo, lib.door.addExit has the same issue and uses that workaround (i.e. reassigning this.sides).
Good luck with your hacking. I hope you'll enjoy the engine. Let me know if you could make it work. Might keep the issue open as a reminder, we should probably explain this restriction on nested objects in the documentation, and I actually have several pending patches to the documentation I should have pushed long ago...
Meant to comment on this yesterday but had some stuff come up. Thanks for the work around. It was either what you suggested, or just not support the nested objects and have them as direct properties. Glad I can have a harvestable trait support multiple things to "harvest".
Not sure if you still wish to keep the issue open, or close it out, but either way the problem has been resolved.
Giving this little engine a go for a little hobby project. Attempting to create a "harvestable" item class to be used by the players. I have created a property to the following:
to which is used by the following sript:
but every time I make an update to the "amount" value, the changes are discarded as soon as the script finishes - as if the state is not being saved. I see that the value gets outputted as 0 remaining, but running the script again results in the same display of 0, running through the same branches again. Am I doing something wrong, or is this type of functionality not supported out of the box?
The text was updated successfully, but these errors were encountered: