Twine Version: 2.x sugar cube 2
[also choose a Story Format tag above]
Looking for some coding help. In my StoryInt passage I have a bunch of variable set but for the sake of the example of what I need help with let’s pick two $Honeycake and $pot and $shards (which is the currency) and they are set to zero. There’s a later passage where you can buy a bunch of items and the way I have done that is giving each item its own silent passage. And all that works and purchasing items has them pass their “is true” evaluation flags in the [[inventory]] passage and values go up as intended. So in the inventory passage I have the value of $Honeycake and $pot (and all the others but keeping this simple) printing so I can track the count along with the value of $shards for tracking that too. Then there are passages [[Sell Apple Pie|SellItems]] and [[Sell Bread|SellItems]] and on that page I’ve got this code to try avoid individual item pages (especially as that is going to grow as development continues).
<<set $itemMap = {
“Honeycake”: “Honeycake”,
“Iron Pot”: “pot”,
“Woolen Blanket”: “blanket”,
“Leather Belt Pouch”: “pouch”,
“Oil Lantern”: “lantern”,
// Add more item mappings as needed
}>>
<<set _selectedItem = $itemMap[$itemName]>>
<<switch _selectedItem>>
<<case "Honeycake">>
<<if $Honeycake !== 0>>
<<set $shards += 10>>
<<set $Honeycake -= 1>>
You sold a honeycake for 10 shards.
<<else>>
<<print "You cannot sell that item.">>
<</if>>
<<break>>
<<case "pot">>
<<if $pot !== 0>>
<<set $shards += 20>>
<<set $pot -= 1>>
You sold an iron pot for 20 shards.
<<else>>
<<print "You cannot sell that item.">>
<</if>>
<<break>>
<<!-- Add more cases for other items as needed -->`Preformatted text`
<</switch>>
I’ve tried all sorts - putting the variable names in to the item map code and everything but it just doesn’t seem to update the values at all and all I get on clicking is a blank page (except for the navigation links at the bottom). If it’s at all relevant I’ve just remembered that there’s <> and it’s closing code containing all this code. Any help would be much appreciated.