Hello everyone, I have a test story on twine (sugarcube2, the latest version on web), really just to figure out how to organize an inventory system along with buying and selling items using currency (gold).
I have some basic code that I used from another user’s topic here, which gives a brief overview of items (names, descriptions, and displaying the information when welcomed at the shop). I added other parts to the first section of code that the user wrote, and my code is just below it. If you visit the link, you’ll understand, but the code I wrote is as follows:
<<set $shop to "shop">> <<set $itemStrawberry to "strawberry">> <<set $frogLiver to "frogman liver">> <<set $magicPole to "Dophire">> <<set $donut to "doughnut">> <<set $cheese to "block of cheese">> "Welcome! Our $shop currently carries:" A $itemStrawberry, for [[5 gold]] Some $frogLiver, with unknown whereabouts, for [[16 gold]] The $magicPole, a sword of legend, sworn to have slain a dragon one thousand years ago, for [[12 gold]] A $donut filled with...something? for [[3 gold]] A $cheese from a live and very healthy goat, for [[7 gold]]
Most of it is very basic, I know, and I’ve only recently (within the past year or so) really advanced in my coding abilities. I mainly write in python 3, so I tried to use knowledge of that language to change the player inventory. I’ve only coded the option to buy frog liver, which is bought for 16 gold, and the resulting passage looks like this:
"Great choice, my friend!" <<set $inventory to $frogLiver>> You have $inventory in your inventory. "would you like anything else?" you have 4 gold left. $donut for [[3 gold|inventory1]]
With the idea that the user starts with 20 gold in their pouch, only a donut can be bought. When you buy a donut, the following will display:
<<set $inventory to $frogLiver, and $donut>> your inventory has: $inventory
The problem occurs when I test my code. I made some changes from the original, which was the inventory being set to its original value and then also including the donut, but the second variable is the only one acknowledged. Basically, every time I click play, it will say my inventory has a donut in it. I want it to say I have my existing item(s), and whatever new item I just added to it.
I’m not sure how to create more than one shop as well. Say I’m in the village and want to buy some fresh(?) goat cheese, and then want to buy medicine in the town for a hefty price. How could I do that? Like if the village has different stock (milk, honey, fish bait, etc) than the town (shield, sturdy net, wrench, etc), how could I show that difference?
The currency variable is its own thing, I’ll try to search some on that so this topic isn’t too loaded with questions, but if I can’t find anything that helps on it, I may ask for more guidance on how this works.
I’m sorry if this is a repeated topic, I was searching about it for maybe half an hour but with so many users and different ideas, this may just be a unique topic that’s never been brought up; however, if it has, I would appreciate being redirected to it.