Making clones of a item.

Chocolatepeanut223
14 Feb 2023, 18:09

I'm making a mining game and I want to make you be able to have multiple "stone" in your inventory at once. Also I want to be able to sell all the "stone" at once. How would I do that?


GeminiNeule
15 Feb 2023, 17:49

First of, there is a tutorial on how to set up a shop that includes some information about cloning objects (stones):
http://docs.textadventures.co.uk/quest/shop.html
http://docs.textadventures.co.uk/quest/clones.html

But: Having multiple objects with the same alias will cause a lot of trouble, since you can not address it specifically. It also may clutter the inventory pane if you use it for your game ("stone", "stone", "stone"). If you really want to stick to the clones, you should make sure they have different names... which would probably look awkward to have "stone 1", "stone 2" and so on in your inventory.

So my suggestion would be to not use clones at all and instead add a quantity attribute to it. Mining "stone" - or different types of ore if you want to extend your game to that - will increase the quantity. When you sell it, the price needs to factor in the quantity sold. You could ask for the quantity to sell or sell all at once. I think I would add a dialog to the shopkeeper for that buy all case or set up a verb that only works when you are in the shop.
If the player sells all stones, you can remove it from the inventory. If you don't want allow the player to buy the stones back from the shop, you can move the stone object to an "offstage" room that is inaccessible by the player. As soon as the player starts mining, move that object back to the player inventory and reset the quantity attribute to 1.
For the inventory you can update the alias to reflect the quantity: stones.alias = "Stones (" + stones.quantity + "x)". Make sure to set up another alias for the stones without the quantity, so using the stones with a verb remains unaffected (like "sell stones" instead of "sell stones (32x)")