Monday, August 21, 2017
Some Quick News
No deep "Monday Musing" today - I've finished the Twine/ Lone Wolf project (it's got 3 more posts, should wrap up next week) and now m working on the follow-up project (that will greatly expand on the work I started) and still thinking about the Combat Cpabilities Map, and doing some thinking about Magic (esp. the "laws of magic" and how to game by laws instead of spells), and chasing down lots of little pop-up thoughts. So a lot that I'm working on, but not a lot going to be posted this week.
Converting Lone Wolf to Twine and SugarCube - Part 7 - Finishing Equipment
Finally, An Inventory System That Actually Works
Okay, more time as passed (you should be glad you can read this all at once instead of watching me working on it :) and I think I finally have it, one widget that will handle all my inventory needs - and cut down the hundreds of lines of code to just a few dozen!Here it is...
:: Initialize [Widget]
<<set $gold = 0>>
<<set $weapons = [ "-empty-", "-empty-" ]>>
<<set $backpack = [ "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-" ]>>
<<set $specialitems = []>>
<<widget "ManageInventory">> <<nobr>>
/*
* Usage: this widget handles the display, removal and addition of all inventory items.
// WARNING : This widget requires several arguments to be passed.
* <<ManageInventory action container item quantity random_min random_max>>
* $args[0] - action: 1 - display, 2 - add item(s), 3 - remove item(s)
* $args[1] - container: 1 - Gold, 2 - Weapons, 3 - Backpack Items, 4 - Special Items, 5 - [if args[0] = 1 (display)] displays all items
* $args[2] - item:
* if adding items- the item name (no quotes needed unless the name has a space; ie, Sword and "Short Sword")
* if removing items- weapon (for a random weapon), backpack (for a random backpack item), or the item name (no quotes) if
a specific item should be searched for and removed
* $args[3] - quantity:
* # - the number of items to change
* random - for a random number (for items this is only 1 at the moment)
* all - to remove all backpack items
* $args[4] - if a random number, the minimum
* $args[5] - if a random number, the maximum
*/
<<switch $args[0]>>
<<case 1>>
<<switch $args[1]>>
<<case 1>> <br> Belt Pouch: $gold Gold Crowns
<<case 2>> <br> Weapons: <<for _wi = 0; _wi < $weapons.length; _wi++>> <<print "<br> " + $weapons[_wi]>> <</for>>
<<case 3>> <br> Backpack Items: <<for _bi = 0; _bi < $backpack.length; _bi++>> <<print "<br> " + $backpack[_bi]>> <</for>>
<<case 4>> <br> Special Items: <<for _si = 0; _si < $specialitems.length; _si++>> <<print "<br> " + $specialitems[_si]>> <</for>>
<<case 5>>
<br> Belt Pouch: $gold Gold Crowns
<br> Weapons: <<for _wi = 0; _wi < $weapons.length; _wi++>> <<print "<br> " + $weapons[_wi]>> <</for>>
<br> Backpack Items: <<for _bi = 0; _bi < $backpack.length; _bi++>> <<print "<br> " + $backpack[_bi]>> <</for>>
<br> Special Items: <<for _si = 0; _si < $specialitems.length; _si++>> <<print "<br> " + $specialitems[_si]>> <</for>>
<</switch>>
<<case 2>>
<<switch $args[1]>>
<<case 1>>
<<if $args[3] != "random">>You pick up $args[3] Gold Crowns, <<set $gold += $args[3]>> <<if $gold > 50>> <<set $gold = 50>> but your Belt Pouch only holds 50 Gold Crowns, <</if>> you now have $gold Gold Crowns.
<<elseif $args[3] == "random">> <<set _goldfound = random ( $args[4], $args[5] )>> You found _goldfound Gold Crowns, <<set $gold += _goldfound>> <<if $gold > 50>> <<set $gold = 50>> but your Belt Pouch only holds 50 Gold Crowns, <</if>> you now have $gold Gold Crowns.
<<else>> Error: Gold amount has not been defined !
<</if>>
<<case 2>>
<span class="wpnreplace">What weapon slot do you want to replace?
<<link " <br> Replace the $weapons[0] with $args[2]">> <<set $weapons[0] = $args[2]>> <<replace .wpnreplace>> You now have a $weapons[0] and a $weapons[1] <</replace>> <</link>>
<<link " <br> Replace the $weapons[1] with $args[2]">> <<set $weapons[1] = $args[2]>> <<replace .wpnreplace>> You now have a $weapons[0] and a $weapons[1] <</replace>> <</link>>
<<link " <br> Do not pick up the items">> <<replace .wpnreplace>> You leave your items unchanged <</replace>> <</link>>
</span>
<<case 3>>
<span class="backreplace">What backpack item do you want to replace?
<<link " <br> Replace the $backpack[0] with $args[2]">> <<set $backpack[0] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[1] with $args[2]">> <<set $backpack[1] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[2] with $args[2]">> <<set $backpack[2] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[3] with $args[2]">> <<set $backpack[3] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[4] with $args[2]">> <<set $backpack[4] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[5] with $args[2]">> <<set $backpack[5] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[6] with $args[2]">> <<set $backpack[6] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[7] with $args[2]">> <<set $backpack[7] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Do not pick up the items">> <<replace .backreplace>> You leave your items unchanged <</replace>> <</link>>
</span>
<<case 4>>
<<if $specialitems.contains ($args[2])>> You already have a $args[2]!
<<else>>
<<run $specialitems.push ($args[2])>> You now have a $args[2].
<</if>>
<</switch>>
<<case 3>>
<<switch $args[1]>>
<<case 1>>
<<if $args[3] != "random">> You have lost $args[3] Gold Crowns, <<set $gold = $gold - $args[3]>> <<if $gold < 0>> <<set $gold = 0>> <</if>> you now have $gold Gold Crowns.
<<elseif $args[3] == "random">> <<set _goldlost = random ( $args[4], $args[5] )>> You have lost _goldlost Gold Crowns, <<set $gold = $gold - _goldlost>> <<if $gold < 0>> <<set $gold = 0>> <</if>> you now have $gold Gold Crowns.
<<else>> Error: Gold amount has not been defined !
<</if>>
<<case 2>>
<<if $args[3] == "random">>
<<set _randomslot = random (1, 2)>>
<<if _randomslot == 1>> <<set $weapons[0] = "-empty-">>You lose your first weapon!
<<elseif _randomslot == 2>> <<set $weapons[1] = "-empty-">>You lose your second weapon!
<</if>>
<<elseif $args[3] == 2>>
<<set $weapons = [ "-empty-", "-empty-" ]>> You have lost all your weapons!
<</if>>
<<case 3>>
<<if $args[3] == "random">>
<<set _randomslot = random (0, 7)>> You lost a backpack item!
<<if _randomslot == 0>> <<set $backpack[0] = "-empty-">>
<<elseif _randomslot == 1>> <<set $backpack[1] = "-empty-">>
<<elseif _randomslot == 2>> <<set $backpack[2] = "-empty-">>
<<elseif _randomslot == 3>> <<set $backpack[3] = "-empty-">>
<<elseif _randomslot == 4>> <<set $backpack[4] = "-empty-">>
<<elseif _randomslot == 5>> <<set $backpack[5] = "-empty-">>
<<elseif _randomslot == 6>> <<set $backpack[6] = "-empty-">>
<<elseif _randomslot == 7>> <<set $backpack[7] = "-empty-">>
<</if>>
<</if>>
<<if $args[3] == "all">>
<<set $backpack = [ "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-" ]>> You have lost all backpack items!
<</if>>
<<case 4>> // remove a special item - not actually used in LW !!
<<else>> Error: Argument for items to remove was not properly defined !
<</switch>>
<<default>>
Error: No state was passed as the first argument to this widget!
<</switch>>
<</nobr>> <</widget>>
<<set $gold = 0>>
<<set $weapons = [ "-empty-", "-empty-" ]>>
<<set $backpack = [ "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-" ]>>
<<set $specialitems = []>>
<<widget "ManageInventory">> <<nobr>>
/*
* Usage: this widget handles the display, removal and addition of all inventory items.
// WARNING : This widget requires several arguments to be passed.
* <<ManageInventory action container item quantity random_min random_max>>
* $args[0] - action: 1 - display, 2 - add item(s), 3 - remove item(s)
* $args[1] - container: 1 - Gold, 2 - Weapons, 3 - Backpack Items, 4 - Special Items, 5 - [if args[0] = 1 (display)] displays all items
* $args[2] - item:
* if adding items- the item name (no quotes needed unless the name has a space; ie, Sword and "Short Sword")
* if removing items- weapon (for a random weapon), backpack (for a random backpack item), or the item name (no quotes) if
a specific item should be searched for and removed
* $args[3] - quantity:
* # - the number of items to change
* random - for a random number (for items this is only 1 at the moment)
* all - to remove all backpack items
* $args[4] - if a random number, the minimum
* $args[5] - if a random number, the maximum
*/
<<switch $args[0]>>
<<case 1>>
<<switch $args[1]>>
<<case 1>> <br> Belt Pouch: $gold Gold Crowns
<<case 2>> <br> Weapons: <<for _wi = 0; _wi < $weapons.length; _wi++>> <<print "<br> " + $weapons[_wi]>> <</for>>
<<case 3>> <br> Backpack Items: <<for _bi = 0; _bi < $backpack.length; _bi++>> <<print "<br> " + $backpack[_bi]>> <</for>>
<<case 4>> <br> Special Items: <<for _si = 0; _si < $specialitems.length; _si++>> <<print "<br> " + $specialitems[_si]>> <</for>>
<<case 5>>
<br> Belt Pouch: $gold Gold Crowns
<br> Weapons: <<for _wi = 0; _wi < $weapons.length; _wi++>> <<print "<br> " + $weapons[_wi]>> <</for>>
<br> Backpack Items: <<for _bi = 0; _bi < $backpack.length; _bi++>> <<print "<br> " + $backpack[_bi]>> <</for>>
<br> Special Items: <<for _si = 0; _si < $specialitems.length; _si++>> <<print "<br> " + $specialitems[_si]>> <</for>>
<</switch>>
<<case 2>>
<<switch $args[1]>>
<<case 1>>
<<if $args[3] != "random">>You pick up $args[3] Gold Crowns, <<set $gold += $args[3]>> <<if $gold > 50>> <<set $gold = 50>> but your Belt Pouch only holds 50 Gold Crowns, <</if>> you now have $gold Gold Crowns.
<<elseif $args[3] == "random">> <<set _goldfound = random ( $args[4], $args[5] )>> You found _goldfound Gold Crowns, <<set $gold += _goldfound>> <<if $gold > 50>> <<set $gold = 50>> but your Belt Pouch only holds 50 Gold Crowns, <</if>> you now have $gold Gold Crowns.
<<else>> Error: Gold amount has not been defined !
<</if>>
<<case 2>>
<span class="wpnreplace">What weapon slot do you want to replace?
<<link " <br> Replace the $weapons[0] with $args[2]">> <<set $weapons[0] = $args[2]>> <<replace .wpnreplace>> You now have a $weapons[0] and a $weapons[1] <</replace>> <</link>>
<<link " <br> Replace the $weapons[1] with $args[2]">> <<set $weapons[1] = $args[2]>> <<replace .wpnreplace>> You now have a $weapons[0] and a $weapons[1] <</replace>> <</link>>
<<link " <br> Do not pick up the items">> <<replace .wpnreplace>> You leave your items unchanged <</replace>> <</link>>
</span>
<<case 3>>
<span class="backreplace">What backpack item do you want to replace?
<<link " <br> Replace the $backpack[0] with $args[2]">> <<set $backpack[0] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[1] with $args[2]">> <<set $backpack[1] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[2] with $args[2]">> <<set $backpack[2] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[3] with $args[2]">> <<set $backpack[3] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[4] with $args[2]">> <<set $backpack[4] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[5] with $args[2]">> <<set $backpack[5] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[6] with $args[2]">> <<set $backpack[6] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[7] with $args[2]">> <<set $backpack[7] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Do not pick up the items">> <<replace .backreplace>> You leave your items unchanged <</replace>> <</link>>
</span>
<<case 4>>
<<if $specialitems.contains ($args[2])>> You already have a $args[2]!
<<else>>
<<run $specialitems.push ($args[2])>> You now have a $args[2].
<</if>>
<</switch>>
<<case 3>>
<<switch $args[1]>>
<<case 1>>
<<if $args[3] != "random">> You have lost $args[3] Gold Crowns, <<set $gold = $gold - $args[3]>> <<if $gold < 0>> <<set $gold = 0>> <</if>> you now have $gold Gold Crowns.
<<elseif $args[3] == "random">> <<set _goldlost = random ( $args[4], $args[5] )>> You have lost _goldlost Gold Crowns, <<set $gold = $gold - _goldlost>> <<if $gold < 0>> <<set $gold = 0>> <</if>> you now have $gold Gold Crowns.
<<else>> Error: Gold amount has not been defined !
<</if>>
<<case 2>>
<<if $args[3] == "random">>
<<set _randomslot = random (1, 2)>>
<<if _randomslot == 1>> <<set $weapons[0] = "-empty-">>You lose your first weapon!
<<elseif _randomslot == 2>> <<set $weapons[1] = "-empty-">>You lose your second weapon!
<</if>>
<<elseif $args[3] == 2>>
<<set $weapons = [ "-empty-", "-empty-" ]>> You have lost all your weapons!
<</if>>
<<case 3>>
<<if $args[3] == "random">>
<<set _randomslot = random (0, 7)>> You lost a backpack item!
<<if _randomslot == 0>> <<set $backpack[0] = "-empty-">>
<<elseif _randomslot == 1>> <<set $backpack[1] = "-empty-">>
<<elseif _randomslot == 2>> <<set $backpack[2] = "-empty-">>
<<elseif _randomslot == 3>> <<set $backpack[3] = "-empty-">>
<<elseif _randomslot == 4>> <<set $backpack[4] = "-empty-">>
<<elseif _randomslot == 5>> <<set $backpack[5] = "-empty-">>
<<elseif _randomslot == 6>> <<set $backpack[6] = "-empty-">>
<<elseif _randomslot == 7>> <<set $backpack[7] = "-empty-">>
<</if>>
<</if>>
<<if $args[3] == "all">>
<<set $backpack = [ "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-" ]>> You have lost all backpack items!
<</if>>
<<case 4>> // remove a special item - not actually used in LW !!
<<else>> Error: Argument for items to remove was not properly defined !
<</switch>>
<<default>>
Error: No state was passed as the first argument to this widget!
<</switch>>
<</nobr>> <</widget>>
Let me walk through it with you...
<<widget "ManageInventory">> <<nobr>>
/*
* Usage: this widget handles the display, removal and addition of all inventory items.
// WARNING : This widget requires several arguments to be passed.
* <<ManageInventory action container item quantity random_min random_max>>
* $args[0] - action: 1 - display, 2 - add item(s), 3 - remove item(s)
* $args[1] - container: 1 - Gold, 2 - Weapons, 3 - Backpack Items, 4 - Special Items, 5 - [if args[0] = 1 (display)] displays all items
* $args[2] - item:
* if adding items- the item name (no quotes needed unless the name has a space; ie, Sword and "Short Sword")
* if removing items- weapon (for a random weapon), backpack (for a random backpack item), or the item name (no quotes) if
a specific item should be searched for and removed
* $args[3] - quantity:
* # - the number of items to change
* random - for a random number (for items this is only 1 at the moment)
* all - to remove all backpack items
* $args[4] - if a random number, the minimum
* $args[5] - if a random number, the maximum
*/ I'm calling this widget <<ManageInventory>>, and putting the <<nobr>> to keep my output pretty. This is in my first Passage, with the “Widget” tag to prevent any problems (per the SugarCube documentation). At the start of it I've got some HTML comments to make notes to myself (and anyone else) about how to use this widget. Taz says documentation is good - and this widget is kind of complicated, it's going to take up to 6 arguments.
First argument will be what to do: display the inventory, add to it or remove from it. There could be another kind, to “use an item” but I'm going to put that in another section [the Lone Wolf items can only be used at certain times].
After what we're doing, the next argument is what container/ type of items are we working on: gold, weapons, backpack items, or special items.
Argument after that is the specific item, or a generic placeholder (the order matters, if you skip this the index of arguments moves - which would be bad).
Final arguments are the specific number of items to work on, or “random” and then the following arguments as the minimum and maximum number.
Takes a bit of getting used to, but isn't too bad. Not everything in this list is done right now, my Lone Wolf book only does limited inventory management - I will fill in the blanks after I get done with this conversion and move on to making my own story.
So let's look at the variables we'll be working with:
<<set $gold = 0>>
<<set $weapons = [ "-empty-", "-empty-" ]>>
<<set $backpack = [ "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-" ]>>
<<set $specialitems = []>>I'm defining arrays for each container (except gold, since it's just a number). I've put that “-empty-” in each available slot so that when I print the contents each empty slot will show up as something. I could have just used “--” or “_” for something shorter (and I may change it to that later). It just needs to print something the player can see and not be totally empty. Except for the Special Items, since they do not get checked or moved like the weapons and backpack items (they mostly just sit quietly in the background).
Okay, so what happens when we want to display the inventory?
<<switch $args[0]>>
<<case 1>>
<<switch $args[1]>>
<<case 1>> <br> Belt Pouch: $gold Gold Crowns
<<case 2>> <br> Weapons: <<for _wi = 0; _wi < $weapons.length; _wi++>> <<print "<br> " + $weapons[_wi]>> <</for>>
<<case 3>> <br> Backpack Items: <<for _bi = 0; _bi < $backpack.length; _bi++>> <<print "<br> " + $backpack[_bi]>> <</for>>
<<case 4>> <br> Special Items: <<for _si = 0; _si < $specialitems.length; _si++>> <<print "<br> " + $specialitems[_si]>> <</for>>
<<case 5>>
<br> Belt Pouch: $gold Gold Crowns
<br> Weapons: <<for _wi = 0; _wi < $weapons.length; _wi++>> <<print "<br> " + $weapons[_wi]>> <</for>>
<br> Backpack Items: <<for _bi = 0; _bi < $backpack.length; _bi++>> <<print "<br> " + $backpack[_bi]>> <</for>>
<br> Special Items: <<for _si = 0; _si < $specialitems.length; _si++>> <<print "<br> " + $specialitems[_si]>> <</for>>
<</switch>>Our first <<switch>> looks at $args[0], the first argument that says what we're doing. A “1” means we're displaying the inventory (not actually changing it). The next <<switch>> looks at $args[1], the second argument of what containers to display. 1 is Gold, 2 is Weapons, 3 the Backpack, 4 Special Items and 5 the whole inventory. For each container we just use a <<for>> loop to read each slot and print it's contents (with the default -empty- if it's empty). Easy.
Adding Items To Inventory
Looking at the stuff you have is bound to make you want more. So how do you pick up stuff? <<case 2>>
<<switch $args[1]>>
<<case 1>>
<<if $args[3] != "random">>You pick up $args[3] Gold Crowns,
<<set $gold += $args[3]>>
<<if $gold > 50>> <<set $gold = 50>> but your Belt Pouch only holds 50 Gold Crowns,
<</if>> you now have $gold Gold Crowns.
<<elseif $args[3] == "random">>
<<set _goldfound = random ( $args[4], $args[5] )>> You found _goldfound Gold Crowns,
<<set $gold += _goldfound>>
<<if $gold > 50>> <<set $gold = 50>> but your Belt Pouch only holds 50 Gold Crowns,
<</if>> you now have $gold Gold Crowns.
<<else>> Error: Gold amount has not been defined !
<</if>>Back to the first <<switch>>, here if $args[0] == 2 then we are adding an item to the inventory. A second <<switch>> and $args[1] == 1 says that we are adding to the gold. Then we check $args[3], the argument for the quantity, and if it is a number we add it, if it is the word “random” we read $arg[4] and $arg[5] for the minimum and maximum to randomly pick from.
Now, in here we're not looking at $arg[2], the specific item, since there is only one item, gold. That argument should still be “gold” or some word, just to keep the arguments index in the right order. Also, there is an <<else>> that will print an error. It isn't a very useful error right now (if you think about the conditions when it would trigger), but it's good to anticipate where things could go wrong and how you could tell yourself what happened (a lesson I keep trying to remember :). You could remove this after finishing your code, I'd leave it in so that even your reader could see where a mistake was. And if you make it say something useful it'll help your reader to report that mistake to you to be fixed.
This is actually just the code I was using in the “Change Gold” Passage from before, if it ain't broke don't fix it.
<<case 2>>
<span class="wpnreplace">What weapon slot do you want to replace?
<<link " <br> Replace the $weapons[0] with $args[2]">>
<<set $weapons[0] = $args[2]>>
<<replace .wpnreplace>> You now have a $weapons[0] and a $weapons[1]
<</replace>>
<</link>>
<<link " <br> Replace the $weapons[1] with $args[2]">>
<<set $weapons[1] = $args[2]>>
<<replace .wpnreplace>> You now have a $weapons[0] and a $weapons[1]
<</replace>>
<</link>>
<<link " <br> Do not pick up the items">>
<<replace .wpnreplace>> You leave your items unchanged <</replace>> <</link>>
</span> Okay, we're still adding items $args[0] == 1, now we're moving on to adding a weapon $args[1] == 2. This gets a little tricky, in an unexpected way. So, we print out 2 lines, one for each weapon slot, showing what the player has in that slot, asking if they want to replace it with the item to be picked up. If they do (by clicking on the <<link>>) we trigger a <<replace>> that replaces the whole block of text. It looks like this...
There's the list of items you can pick up (a sword, dagger or axe), so you click on the one you want...
So, what slot do I want to replace with the Sword? Both are empty. Or, I could choose not to pick up the item (though, that will get rid of the original link, so I won't be able to pick it up again - I'm not sure how to fix that, not too worried about it at the moment). But I want it, so I pick whichever slot..
Great, now I have a Sword. But I have another empty slot, so why not pick up one of the other weapons?
Okay, now I can get the Dagger. I can put it in the empty slot, or replace the Sword, whatever I want (and which took a whole ton of code the last way I did this).
So now I have a Dagger, um... twice? That looks a little confusing...
Let's talk about something in CSS...
CSS IDs and Classes
When we do a <<replace>> we need some kind of target, something to be replaced. Before this I had been using IDs (like <span id="replace_this">). An ID is supposed to be unique on the page, in Twine I'm trying to make it unique to the whole story. One Id to one element. But there is another selector, a “Class.” A Class is meant to belong to several items, so <span class="warning_message"> could be used for every place there needs to be some kind of warning (like we did way back at the beginning).So why do I bring this up now? Well, that funny thing above where each line had the same text, that's because the <<ManageInventory>> widget is using a class: <span class="wpnreplace"> and <<replace .wpnreplace>> (for the <<replace>> when you target an Id you use #name and a class is targeted with .name).
Well, that's silly - why not use an Id instead then?
Um... that looks even weirder...
Because the Id is unique, each link to pick up an item keeps overwriting the one before it, and doesn't get rid of the links for what slot to put the item in (so you could keep picking up the same item forever). That really didn't work right. So I changed it to using a class and while it looks funny, there is no "infinite item glitch" that way. I really do need to revisit this and see how to clean it up some more, which will be one of the long list of things to fix down the road (I have a feeling it will be an easy fix, I'm just a little overwhelmed with this inventory stuff right now).
Okay, where was I again?
Oh yeah, now we can add a weapon, we just let the player choose where.
Adding a Backpack Item is pretty much exactly the same thing, we just have 8 Backpack slots compared to only 2 Weapons.
<<case 3>>
<span class="backreplace">What backpack item do you want to replace?
<<link " <br> Replace the $backpack[0] with $args[2]">> <<set $backpack[0] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[1] with $args[2]">> <<set $backpack[1] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[2] with $args[2]">> <<set $backpack[2] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[3] with $args[2]">> <<set $backpack[3] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[4] with $args[2]">> <<set $backpack[4] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[5] with $args[2]">> <<set $backpack[5] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[6] with $args[2]">> <<set $backpack[6] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Replace the $backpack[7] with $args[2]">> <<set $backpack[7] = $args[2]>> <<replace .backreplace>> You have gained a $args[2] <</replace>> <</link>>
<<link " <br> Do not pick up the items">> <<replace .backreplace>> You leave your items unchanged <</replace>> <</link>>
</span> Again, the presentation is not the greatest - I'm going to need to work on making everything look neat and easy to read. But it does work, and after the last several days of banging my head against the wall on this, I'm okay with ugly-but-works for now.
Adding a Special Item is stupidly easy.
<<case 4>>
<<if $specialitems.contains ($args[2])>> You already have a $args[2]!
<<else>>
<<run $specialitems.push ($args[2])>> You now have a $args[2].
<</if>>The system tells you if you already have one, or adds it to the array if you don't. Thankfully Special Items do not get moved around, either you have them or you don't.
And that's it - now we have an inventory system that will let you view your items and add items, including letting you replace existing items with new ones. All at a fraction of the code I was working on before, and all from one central source.
Taking Out The Trash
So we can add items in our new inventory system, what about getting rid of them?Well, that's not a problem either. All the removals are $args[0] == 3, so our first <<switch>> looks for that, and again a second <<switch>> looks at $args[1] for what container we're removing an item from.
<<if $args[3] != "random">> You have lost $args[3] Gold Crowns,
<<set $gold = $gold - $args[3]>>
<<if $gold < 0>> <<set $gold = 0>> <</if>> you now have $gold Gold Crowns.
<<elseif $args[3] == "random">>
<<set _goldlost = random ( $args[4], $args[5] )>> You have lost _goldlost Gold Crowns,
<<set $gold = $gold - _goldlost>> <<if $gold < 0>> <<set $gold = 0>> <</if>> you now have $gold Gold Crowns.
<<else>> Error: Gold amount has not been defined !
<</if>>Again, using the old code, removing gold is easy, and checks for a specific number or a random number. Just like the code to add, but in reverse.
<<if $args[3] == "random">>
<<set _randomslot = random (1, 2)>>
<<if _randomslot == 1>> <<set $weapons[0] = "-empty-">>You lose your first weapon!
<<elseif _randomslot == 2>> <<set $weapons[1] = "-empty-">>You lose your second weapon!
<</if>>
<<elseif $args[3] == 2>>
<<set $weapons = [ "-empty-", "-empty-" ]>> You have lost all your weapons!
<</if>>The code to remove a Weapon is a little funny right now. All I'm testing for is 2 things - weather to remove 1 random weapon or weather to remove all of them. Because, in the Lone Wolf books that's all that ever happens. I can and should set up a way to remove a specific item (like just a Sword, if you had one) and will, later. Again, I just want to get my basic code working, breathe, and then expand on and refine it.
<<if $args[3] == "random">>
<<set _randomslot = random (0, 7)>> You lost a backpack item!
<<if _randomslot == 0>> <<set $backpack[0] = "-empty-">>
<<elseif _randomslot == 1>> <<set $backpack[1] = "-empty-">>
<<elseif _randomslot == 2>> <<set $backpack[2] = "-empty-">>
<<elseif _randomslot == 3>> <<set $backpack[3] = "-empty-">>
<<elseif _randomslot == 4>> <<set $backpack[4] = "-empty-">>
<<elseif _randomslot == 5>> <<set $backpack[5] = "-empty-">>
<<elseif _randomslot == 6>> <<set $backpack[6] = "-empty-">>
<<elseif _randomslot == 7>> <<set $backpack[7] = "-empty-">>
<</if>>
<</if>>
<<if $args[3] == "all">>
<<set $backpack = [ "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-", "-empty-" ]>> You have lost all backpack items!
<</if>>Backpack Items are the same way, we either clear one random slot or all of them - again, all that ever happens in the game. Again, needs to be fleshed out down the road.
Thankfully, you never lose Special Items - so I'm totally ignoring that section :)
And that's it - view, add and remove items ; what else do you really need an inventory system to do?
One last comment before we finally move on from Inventory (thankfully)...
Test, Test, Test
Writing code is complicated, you need to think it through, write it a piece at a time, and then test it a lot. While working on this system I made a few Passages just to play with adding and removing items...This is a vital step. I made a ton of errors, both large and small, I had the whole unexpected display difference between Ids and Classes, there was a lot of work to refine this (and it's not even finished, so there's still more work to do!). Trying to write everything out and then wade through the errors would be a disaster. It would be so frustrating, so overwhelming, so hard to track exactly where an error came from - no fun. So write a bit, make a Passage and test it, write some more, update the test Passage and test, rinse, wash, repeat. That will make your coding into a series of small, manageable disasters - and give you some small, regular success to see that you really are getting somewhere. Coding is work, make it as easy on yourself as possible.
Okay, that's it. The inventory system will still need some work, but it's close enough to done that I want to move on and get the last chunk of the game rules out of the way... Combat.
Friday, August 18, 2017
Converting Lone Wolf to Twine and SugarCube - Part 6 - Equipment Gone Wild
Okay, another day after another night of writing, revising and cursing code. I'm trying to add the code to handle Backpack items, dropping them and picking up only part of a group. It isn't working (as usual, I've put several hours into it and while I'm getting there, I'm not there yet). Thing is, once I get it working I have to copy and modify it for the other 3 types of backpack items - so more copy-paste-change variables-copy-paste like I did for the weapons. Now, just above I posted how the code for 1 Weapon has increased - with some placeholders for the unfinished stuff, here is roughly how big ALL the equipment code is going to be when I get it working...
<<switch $founditem[0]>>
<<case "Gold">>
You pick up $founditem[1] Gold Crowns,
<<set $Gold = $Gold + $founditem[1]>>
<<if $Gold > 50>>
<<set $Gold = 50>>
but your Belt Pouch only holds 50 Gold Crowns,
<</if>>
you now have $Gold Gold Crowns.
<<case "Helmet">>
<<if $Helmet > 0>>You are already wearing a helmet!
<<else>>
<<set $Helmet = 1>>You put on the Helmet.
<</if>>
<<case "Armor">>
<<if $Armor > 0>>You are already wearing armor!
<<else>>
<<set $Armor = 1>>You put on the Chainmail Waistcoat.
<</if>>
<<case "Dagger">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Daggers == 0>>
<<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>
<<elseif $Daggers == 1>>You already have a Dagger, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Daggers = 2>>You now have 2 Daggers.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Daggers == 2>>You already have two Daggers, your hands are full!
<<elseif $Daggers == 1>>
You already have a Dagger! Do you want to drop your other weapon and have 2 Daggers instead?
<<linkreplace " Yes">>
<<set $Daggers = 2>>
<<if $Spears == 1>><<set $Spears = 0>><<elseif $Maces == 1>><<set $Maces = 0>><<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Axes == 1>><<set $Axes = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>><<elseif $Broadswords == 1>><<set $Broadswords = 0>>
<</if>>
You now have 2 Daggers.<</linkreplace>><<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Daggers == 0>>
What item do you want to drop to make room for the Dagger?
<<if $Spears >= 1>>
<<linkreplace " the Spear">><<set $Spears-->><<set $Daggers = 1>>You drop your Spear and gain a Dagger.<</linkreplace>><</if>>
<<if $Maces >= 1>>
<<linkreplace " the Mace">><<set $Maces-->><<set $Daggers = 1>>You drop your Mace and gain a Dagger.<</linkreplace>><</if>>
<<if $ShortSwords >= 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords-->><<set $Daggers = 1>>You drop your Short Sword and gain a Dagger.<</linkreplace>><</if>>
<<if $Warhammers >= 1>>
<<linkreplace " the Warhammer">><<set $Warhammers-->><<set $Daggers = 1>>You drop your Warhammer and gain a Dagger.<</linkreplace>><</if>>
<<if $Swords >= 1>>
<<linkreplace " the Sword">><<set $Swords-->><<set $Daggers = 1>>You drop your Sword and gain a Dagger.<</linkreplace>><</if>>
<<if $Axes >= 1>>
<<linkreplace " the Axe">><<set $Axes-->><<set $Daggers = 1>>You drop your Axe and gain a Dagger.<</linkreplace>><</if>>
<<if $Quarterstaffs >= 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs-->><<set $Daggers = 1>>You drop your Quarterstaff and gain a Dagger.<</linkreplace>><</if>>
<<if $Broadswords >= 1>>
<<linkreplace " the Broadsword">><<set $Broadswords-->><<set $Daggers = 1>>You drop your Broadsword and gain a Dagger.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Spear">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Spears = 1>>You pick up the Spear.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Spears == 0>>
<<set $Spears = 1>>You pick up the Spear.<<set $CountHands++>>
<<elseif $Spears == 1>>You already have a Spear, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Spears = 2>>You now have 2 Spears.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Spears == 2>>You already have two Spears, your hands are full!
<<elseif $Spears == 1>>
You already have a Spear! Do you want to drop your other weapon and have 2 Spears instead?
<<linkreplace " Yes">><<set $Spears = 2>><<if $Daggers == 1>><<set $Daggers = 0>><<elseif $Maces == 1>><<set $Maces = 0>><<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Axes == 1>><<set $Axes = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>><<elseif $Broadswords == 1>><<set $Broadswords = 0>>
<</if>>
You now have 2 Spears.<</linkreplace>><<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Spears == 0>>
What item do you want to drop to make room for the Spear?
<<if $Daggers >= 1>>
<<linkreplace " the Dagger">><<set $Daggers-->><<set $Spears = 1>>You drop your Dagger and gain a Spear.<</linkreplace>><</if>>
<<if $Maces >= 1>>
<<linkreplace " the Mace">><<set $Maces-->><<set $Spears = 1>>You drop your Mace and gain a Spear.<</linkreplace>><</if>>
<<if $ShortSwords >= 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords-->><<set $Spears = 1>>You drop your Short Sword and gain a Spear.<</linkreplace>><</if>>
<<if $Warhammers >= 1>>
<<linkreplace " the Warhammer">><<set $Warhammers-->><<set $Spears = 1>>You drop your Warhammer and gain a Spear.<</linkreplace>><</if>>
<<if $Swords >= 1>>
<<linkreplace " the Sword">><<set $Swords-->><<set $Spears = 1>>You drop your Sword and gain a Spear.<</linkreplace>><</if>>
<<if $Axes >= 1>>
<<linkreplace " the Axe">><<set $Axes-->><<set $Spears = 1>>You drop your Axe and gain a Spear.<</linkreplace>><</if>>
<<if $Quarterstaffs >= 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs-->><<set $Spears = 1>>You drop your Quarterstaff and gain a Spear.<</linkreplace>><</if>>
<<if $Broadswords >= 1>>
<<linkreplace " the Broadsword">><<set $Broadswords-->><<set $Spears = 1>>You drop your Broadsword and gain a Spear.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Mace">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Maces = 1>>You pick up the Mace.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Maces == 0>>
<<set $Maces = 1>>You pick up the Mace.<<set $CountHands++>>
<<elseif $Maces == 1>>You already have a Mace, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Maces = 2>>You now have 2 Maces.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Maces == 2>>You already have two Maces, your hands are full!
<<elseif $Maces == 1>>
You already have a Mace! Do you want to drop your other weapon and have 2 Maces instead?
<<linkreplace " Yes">><<set $Maces = 2>><<if $Daggers == 1>><<set $Daggers = 0>><<elseif $Spears == 1>><<set $Spears = 0>><<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Axes == 1>><<set $Axes = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>><<elseif $Broadswords == 1>><<set $Broadswords = 0>>
<</if>>
You now have 2 Maces.<</linkreplace>><<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Maces == 0>>
What item do you want to drop to make room for the Mace?
<<if $Daggers >= 1>>
<<linkreplace " the Dagger">><<set $Daggers-->><<set $Maces = 1>>You drop your Dagger and gain a Mace.<</linkreplace>><</if>>
<<if $Spears >= 1>>
<<linkreplace " the Spear">><<set $Spears-->><<set $Maces = 1>>You drop your Spear and gain a Mace.<</linkreplace>><</if>>
<<if $ShortSwords >= 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords-->><<set $Maces = 1>>You drop your Short Sword and gain a Mace.<</linkreplace>><</if>>
<<if $Warhammers >= 1>>
<<linkreplace " the Warhammer">><<set $Warhammers-->><<set $Maces = 1>>You drop your Warhammer and gain a Mace.<</linkreplace>><</if>>
<<if $Swords >= 1>>
<<linkreplace " the Sword">><<set $Swords-->><<set $Maces = 1>>You drop your Sword and gain a Mace.<</linkreplace>><</if>>
<<if $Axes >= 1>>
<<linkreplace " the Axe">><<set $Axes-->><<set $Maces = 1>>You drop your Axe and gain a Mace.<</linkreplace>><</if>>
<<if $Quarterstaffs >= 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs-->><<set $Maces = 1>>You drop your Quarterstaff and gain a Mace.<</linkreplace>><</if>>
<<if $Broadswords >= 1>>
<<linkreplace " the Broadsword">><<set $Broadswords-->><<set $Maces = 1>>You drop your Broadsword and gain a Mace.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Short Sword">>
<<nobr>>
<<if $CountHands == 0>>
<<set $ShortSwords = 1>>You pick up the Short Sword.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $ShortSwords == 0>>
<<set $ShortSwords = 1>>You pick up the Short Sword.<<set $CountHands++>>
<<elseif $ShortSwords == 1>>You already have a Short Sword, do you want to pick up a spare?
<<linkreplace " Yes">><<set $ShortSwords = 2>>You now have 2 Short Swords.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $ShortSwords == 2>>You already have two Short Swords, your hands are full!
<<elseif $ShortSwords == 1>>
You already have a Short Sword! Do you want to drop your other weapon and have 2 Short Swords instead?
<<linkreplace " Yes">><<set $ShortSwords = 2>><<if $Daggers == 1>><<set $Daggers = 0>><<elseif $Spears == 1>><<set $Spears = 0>><<elseif $Maces == 1>><<set $Maces = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Axes == 1>><<set $Axes = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>><<elseif $Broadswords == 1>><<set $Broadswords = 0>>
<</if>>
You now have 2 Short Swords.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $ShortSwords == 0>>
What item do you want to drop to make room for the Short Sword?
<<if $Daggers >= 1>>
<<linkreplace " the Dagger">><<set $Daggers-->><<set $ShortSwords = 1>>You drop your Dagger and gain a Short Sword.<</linkreplace>><</if>>
<<if $Spears >= 1>>
<<linkreplace " the Spear">><<set $Spears-->><<set $ShortSwords = 1>>You drop your Spear and gain a Short Sword.<</linkreplace>><</if>>
<<if $Maces >= 1>>
<<linkreplace " the Mace">><<set $Maces-->><<set $ShortSwords = 1>>You drop your Mace and gain a Short Sword.<</linkreplace>><</if>>
<<if $Warhammers >= 1>>
<<linkreplace " the Warhammer">><<set $Warhammers-->><<set $ShortSwords = 1>>You drop your Warhammer and gain a Short Sword.<</linkreplace>><</if>>
<<if $Swords >= 1>>
<<linkreplace " the Sword">><<set $Swords-->><<set $ShortSwords = 1>>You drop your Sword and gain a Short Sword.<</linkreplace>><</if>>
<<if $Axes >= 1>>
<<linkreplace " the Axe">><<set $Axes-->><<set $ShortSwords = 1>>You drop your Axe and gain a Short Sword.<</linkreplace>><</if>>
<<if $Quarterstaffs >= 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs-->><<set $ShortSwords = 1>>You drop your Quarterstaff and gain a Short Sword.<</linkreplace>><</if>>
<<if $Broadswords >= 1>>
<<linkreplace " the Broadsword">><<set $Broadswords-->><<set $ShortSwords = 1>>You drop your Broadsword and gain a Short Sword.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Warhammer">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Warhammers = 1>>You pick up the Warhammer.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Warhammers == 0>>
<<set $Warhammers = 1>>You pick up the Warhammer.<<set $CountHands++>>
<<elseif $Warhammers == 1>>You already have a Warhammer, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Warhammers = 2>>You now have 2 Warhammers.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Warhammers == 2>>You already have two Warhammers, your hands are full!
<<elseif $Warhammers == 1>>
You already have a Warhammer! Do you want to drop your other weapon and have 2 Warhammers instead?
<<linkreplace " Yes">><<set $Warhammers = 2>><<if $Daggers == 1>><<set $Daggers = 0>><<elseif $Spears == 1>><<set $Spears = 0>><<elseif $Maces == 1>><<set $Maces = 0>><<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Axes == 1>><<set $Axes = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>><<elseif $Broadswords == 1>><<set $Broadswords = 0>>
<</if>>You now have 2 Warhammers.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Warhammers == 0>>
What item do you want to drop to make room for the Warhammer?
<<if $Daggers >= 1>>
<<linkreplace " the Dagger">><<set $Daggers-->><<set $Warhammers = 1>>You drop your Dagger and gain a Warhammer.<</linkreplace>><</if>>
<<if $Spears >= 1>>
<<linkreplace " the Spear">><<set $Spears-->><<set $Warhammers = 1>>You drop your Spear and gain a Warhammer.<</linkreplace>><</if>>
<<if $Maces >= 1>>
<<linkreplace " the Mace">><<set $Maces-->><<set $Warhammers = 1>>You drop your Mace and gain a Warhammer.<</linkreplace>><</if>>
<<if $ShortSwords >= 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords-->><<set $Warhammers = 1>>You drop your Short Sword and gain a Warhammer.<</linkreplace>><</if>>
<<if $Swords >= 1>>
<<linkreplace " the Sword">><<set $Swords-->><<set $Warhammers = 1>>You drop your Sword and gain a Warhammer.<</linkreplace>><</if>>
<<if $Axes >= 1>>
<<linkreplace " the Axe">><<set $Axes-->><<set $Warhammers = 1>>You drop your Axe and gain a Warhammer.<</linkreplace>><</if>>
<<if $Quarterstaffs >= 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs-->><<set $Warhammers = 1>>You drop your Quarterstaff and gain a Warhammer.<</linkreplace>><</if>>
<<if $Broadswords >= 1>>
<<linkreplace " the Broadsword">><<set $Broadswords-->><<set $Warhammers = 1>>You drop your Broadsword and gain a Warhammer.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Sword">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Swords = 1>>You pick up the Sword.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Swords == 0>>
<<set $Swords = 1>>You pick up the Sword.<<set $CountHands++>>
<<elseif $Swords == 1>>You already have a Sword, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Swords = 2>>You now have 2 Swords.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Swords == 2>>You already have two Swords, your hands are full!
<<elseif $Swords == 1>>
You already have a Sword! Do you want to drop your other weapon and have 2 Swords instead?
<<linkreplace " Yes">><<set $Swords = 2>><<if $Daggers == 1>><<set $Daggers = 0>><<elseif $Spears == 1>><<set $Spears = 0>><<elseif $Maces == 1>><<set $Maces = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Axes == 1>><<set $Axes = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>><<elseif $Broadswords == 1>><<set $Broadswords = 0>>
<</if>>You now have 2 Swords.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Swords == 0>>
What item do you want to drop to make room for the Sword?
<<if $Daggers >= 1>>
<<linkreplace " the Dagger">><<set $Daggers-->><<set $Swords = 1>>You drop your Dagger and gain a Sword.<</linkreplace>><</if>>
<<if $Spears >= 1>>
<<linkreplace " the Spear">><<set $Spears-->><<set $Swords = 1>>You drop your Spear and gain a Sword.<</linkreplace>><</if>>
<<if $Maces >= 1>>
<<linkreplace " the Mace">><<set $Maces-->><<set $Swords = 1>>You drop your Mace and gain a Sword.<</linkreplace>><</if>>
<<if $ShortSwords >= 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords-->><<set $Swords = 1>>You drop your Short Sword and gain a Sword.<</linkreplace>><</if>>
<<if $Warhammers >= 1>>
<<linkreplace " the Warhammer">><<set $Warhammers-->><<set $Swords = 1>>You drop your Warhammer and gain a Sword.<</linkreplace>><</if>>
<<if $Axes >= 1>>
<<linkreplace " the Axe">><<set $Axes-->><<set $Swords = 1>>You drop your Axe and gain a Sword.<</linkreplace>><</if>>
<<if $Quarterstaffs >= 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs-->><<set $Swords = 1>>You drop your Quarterstaff and gain a Sword.<</linkreplace>><</if>>
<<if $Broadswords >= 1>>
<<linkreplace " the Broadsword">><<set $Broadswords-->><<set $Swords = 1>>You drop your Broadsword and gain a Sword.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Axe">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Axes = 1>>You pick up the Axe.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Axes == 0>>
<<set $Axes = 1>>You pick up the Axe.<<set $CountHands++>>
<<elseif $Axes == 1>>You already have an Axe, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Axes = 2>>You now have 2 Axes.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Axes == 2>>You already have two Axes, your hands are full!
<<elseif $Axes == 1>>
You already have an Axe! Do you want to drop your other weapon and have 2 Axes instead?
<<linkreplace " Yes">><<set $Axes = 2>><<if $Daggers == 1>><<set $Daggers = 0>><<elseif $Spears == 1>><<set $Spears = 0>><<elseif $Maces == 1>><<set $Maces = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>><<elseif $Broadsword == 1>><<set $Broadsword = 0>>
<</if>>You now have 2 Axes.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Axes == 0>>
What item do you want to drop to make room for the Axe?
<<if $Daggers >= 1>>
<<linkreplace " the Dagger">><<set $Daggers-->><<set $Axes = 1>>You drop your Dagger and gain an Axe.<</linkreplace>><</if>>
<<if $Spears >= 1>>
<<linkreplace " the Spear">><<set $Spears-->><<set $Axes = 1>>You drop your Spear and gain an Axe.<</linkreplace>><</if>>
<<if $Maces >= 1>>
<<linkreplace " the Mace">><<set $Maces-->><<set $Axes = 1>>You drop your Mace and gain an Axe.<</linkreplace>><</if>>
<<if $ShortSwords >= 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords-->><<set $Axes = 1>>You drop your Short Sword and gain an Axe.<</linkreplace>><</if>>
<<if $Warhammers >= 1>>
<<linkreplace " the Warhammer">><<set $Warhammers-->><<set $Axes = 1>>You drop your Warhammer and gain an Axe.<</linkreplace>><</if>>
<<if $Swords >= 1>>
<<linkreplace " the Sword">><<set $Swords-->><<set $Axes = 1>>You drop your Sword and gain an Axe.<</linkreplace>><</if>>
<<if $Quarterstaffs >= 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs-->><<set $Axes = 1>>You drop your Quarterstaff and gain an Axe.<</linkreplace>><</if>>
<<if $Broadsword >= 1>>
<<linkreplace " the Broadsword">><<set $Broadsword-->><<set $Axes = 1>>You drop your Broadsword and gain an Axe.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Quarterstaff">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Quarterstaffs = 1>>You pick up the Quarterstaff.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Quarterstaffs == 0>>
<<set $Quarterstaffs = 1>>You pick up the Quarterstaff.<<set $CountHands++>>
<<elseif $Quarterstaffs == 1>>You already have a Quarterstaff, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Quarterstaffs = 2>>You now have 2 Quarterstaffs.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Quarterstaffs == 2>>You already have two Quarterstaffs, your hands are full!
<<elseif $Quarterstaffs == 1>>
You already have a Quarterstaff! Do you want to drop your other weapon and have 2 Quarterstaffs instead?
<<linkreplace " Yes">><<set $Quarterstaffs = 2>><<if $Daggers == 1>><<set $Daggers = 0>><<elseif $Spears == 1>><<set $Spears = 0>><<elseif $Maces == 1>><<set $Maces = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Axes == 1>><<set $Axes = 0>><<elseif $Broadsword == 1>><<set $Broadsword = 0>>
<</if>>You now have 2 Quarterstaffs.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Quarterstaffs == 0>>
What item do you want to drop to make room for the Quarterstaff?
<<if $Daggers >= 1>>
<<linkreplace " the Dagger">><<set $Daggers-->><<set $Quarterstaffs = 1>>You drop your Dagger and gain a Quarterstaff.<</linkreplace>><</if>>
<<if $Spears >= 1>>
<<linkreplace " the Spear">><<set $Spears-->><<set $Quarterstaffs = 1>>You drop your Spear and gain a Quarterstaff.<</linkreplace>><</if>>
<<if $Maces >= 1>>
<<linkreplace " the Mace">><<set $Maces-->><<set $Quarterstaffs = 1>>You drop your Mace and gain aQuarterstaff.<</linkreplace>><</if>>
<<if $ShortSwords >= 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords-->><<set $Quarterstaffs = 1>>You drop your Short Sword and gain a Quarterstaff.<</linkreplace>><</if>>
<<if $Warhammers >= 1>>
<<linkreplace " the Warhammer">><<set $Warhammers-->><<set $Quarterstaffs = 1>>You drop your Warhammer and gain a Quarterstaff.<</linkreplace>><</if>>
<<if $Swords >= 1>>
<<linkreplace " the Sword">><<set $Swords-->><<set $Quarterstaffs = 1>>You drop your Sword and gain a Quarterstaff.<</linkreplace>><</if>>
<<if $Axes >= 1>>
<<linkreplace " the Axe">><<set $Axes-->><<set $Quarterstaffs = 1>>You drop your Axe and gain a Quarterstaff.<</linkreplace>><</if>>
<<if $Broadsword >= 1>>
<<linkreplace " the Broadsword">><<set $Broadsword-->><<set $Quarterstaffs = 1>>You drop your Broadsword and gain a Quarterstaff.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Broadsword">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Broadswords = 1>>You pick up the Broadsword.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Broadswords == 0>>
<<set $Broadswords = 1>>You pick up the Broadsword.<<set $CountHands++>>
<<elseif $Broadswords == 1>>You already have a Broadsword, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Broadswords = 2>>You now have 2 Broadswords.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Broadswords == 2>>You already have two Broadswords, your hands are full!
<<elseif $Broadswords == 1>>
You already have a Broadsword! Do you want to drop your other weapon and have 2 Broadswords instead?
<<linkreplace " Yes">><<set $Broadswords = 2>><<if $Daggers == 1>><<set $Daggers = 0>><<elseif $Spears == 1>><<set $Spears = 0>><<elseif $Maces == 1>><<set $Maces = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Axes == 1>><<set $Axes = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>>
<</if>>You now have 2 Broadswords.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Broadswords == 0>>
What item do you want to drop to make room for the Broadsword?
<<if $Daggers >= 1>>
<<linkreplace " the Dagger">><<set $Daggers-->><<set $Broadswords = 1>>You drop your Dagger and gain a Broadsword.<</linkreplace>><</if>>
<<if $Spears >= 1>>
<<linkreplace " the Spear">><<set $Spears-->><<set $Broadswords = 1>>You drop your Spear and gain a Broadsword.<</linkreplace>><</if>>
<<if $Maces >= 1>>
<<linkreplace " the Mace">><<set $Maces-->><<set $Broadswords = 1>>You drop your Mace and gain a Broadsword.<</linkreplace>><</if>>
<<if $ShortSwords >= 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords-->><<set $Broadswords = 1>>You drop your Short Sword and gain a Broadsword.<</linkreplace>><</if>>
<<if $Warhammers >= 1>>
<<linkreplace " the Warhammer">><<set $Warhammers-->><<set $Broadswords = 1>>You drop your Warhammer and gain a Broadsword.<</linkreplace>><</if>>
<<if $Swords >= 1>>
<<linkreplace " the Sword">><<set $Swords-->><<set $Broadswords = 1>>You drop your Sword and gain a Broadsword.<</linkreplace>><</if>>
<<if $Axes >= 1>>
<<linkreplace " the Axe">><<set $Axes-->><<set $Broadswords = 1>>You drop your Axe and gain a Broadsword.<</linkreplace>><</if>>
<<if $Quarterstaffs >= 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs-->><<set $Broadswords = 1>>You drop your Quarterstaff and gain a Broadsword.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>><</if>><</if>><</nobr>>
<<case "Health Potion">>
<<nobr>>
<<set _freespace = 8 - $CountBackpack>>
<<if $founditem[1] <= _freespace>>
<<set $HealthPotions = $HealthPotions + $founditem[1]>>You now have $HealthPotions Health Potions.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>
<<elseif $founditem[1] > _freespace>>
You don't have room for that many items. Do you want to...Drop some of the items you are carrying?
<span id="dropitems1">
<<if $MealOfLaumspur > 0>>How many Meals of Laumspur do you want to drop?
<<if $MealOfLaumspur >= 1>><<link " One">><<set $MealOfLaumspur = $MealOfLaumspur - 1>><<set $CountBackpack = $CountBackpack - 1>><<replace #dropitems1>>You drop 1 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 2>><<link " Two">><<set $MealOfLaumspur = $MealOfLaumspur - 2>><<set $CountBackpack = $CountBackpack - 2>><<replace #dropitems1>>You drop 2 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 3>><<link " Three">><<set $MealOfLaumspur = $MealOfLaumspur - 3>><<set $CountBackpack = $CountBackpack - 3>><<replace #dropitems1>>You drop 3 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 4>><<link " Four">><<set $MealOfLaumspur = $MealOfLaumspur - 4>><<set $CountBackpack = $CountBackpack - 4>><<replace #dropitems1>>You drop 4 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 5>><<link " Five">><<set $MealOfLaumspur = $MealOfLaumspur - 5>><<set $CountBackpack = $CountBackpack - 5>><<replace #dropitems1>>You drop 5 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 6>><<link " Six">><<set $MealOfLaumspur = $MealOfLaumspur - 6>><<set $CountBackpack = $CountBackpack - 6>><<replace #dropitems1>>You drop 6 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 7>><<link " Seven">><<set $MealOfLaumspur = $MealOfLaumspur - 7>><<set $CountBackpack = $CountBackpack - 7>><<replace #dropitems1>>You drop 7 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 8>><<link " Eight">><<set $MealOfLaumspur = $MealOfLaumspur - 8>><<set $CountBackpack = $CountBackpack - 8>><<replace #dropitems1>>You drop 8 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
</span>
<span id="dropitems2">
<<if $StrengthPotion > 0>>How many Strength Potions do you want to drop?
<<if $StrengthPotion >= 1>><<link " One">><<set $StrengthPotion = $StrengthPotion - 1>><<set $CountBackpack = $CountBackpack - 1>><<replace #dropitems2>>You drop 1 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 2>><<link " Two">><<set $StrengthPotion = $StrengthPotion - 2>><<set $CountBackpack = $CountBackpack - 2>><<replace #dropitems2>>You drop 2 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 3>><<link " Three">><<set $StrengthPotion = $StrengthPotion - 3>><<set $CountBackpack = $CountBackpack - 3>><<replace #dropitems2>>You drop 3 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 4>><<link " Four">><<set $StrengthPotion = $StrengthPotion - 4>><<set $CountBackpack = $CountBackpack - 4>><<replace #dropitems2>>You drop 4 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 5>><<link " Five">><<set $StrengthPotion = $StrengthPotion - 5>><<set $CountBackpack = $CountBackpack - 5>><<replace #dropitems2>>You drop 5 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 6>><<link " Six">><<set $StrengthPotion = $StrengthPotion - 6>><<set $CountBackpack = $CountBackpack - 6>><<replace #dropitems2>>You drop 6 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 7>><<link " Seven">><<set $StrengthPotion = $StrengthPotion - 7>><<set $CountBackpack = $CountBackpack - 7>><<replace #dropitems2>>You drop 7 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>
<<if $StrengthPotion >= 8>><<link " Eight">><<set $StrengthPotion = $StrengthPotion - 8>><<set $CountBackpack = $CountBackpack - 8>><<replace #dropitems2>>You drop 8 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<</if>><</if>></span>
<span id="qtypickup">Do you want to pick up only some of the Health Potions?
<<if _freespace >= 1>><<link " One">><<set $HealthPotions = $HealthPotions + 1>><<set $CountBackpack = $CountBackpack + 1>><<replace #qtypickup>>You pick up 1 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 2>><<link " Two">><<set $HealthPotions = $HealthPotions + 2>><<set $CountBackpack = $CountBackpack + 2>><<replace #qtypickup>>You pick up 2 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 3>><<link " Three">><<set $HealthPotions = $HealthPotions + 3>><<set $CountBackpack = $CountBackpack + 3>><<replace #qtypickup>>You pick up 3 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 4>><<link " Four">><<set $HealthPotions = $HealthPotions + 4>><<set $CountBackpack = $CountBackpack + 4>><<replace #qtypickup>>You pick up 4 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 5>><<link " Five">><<set $HealthPotions = $HealthPotions + 5>><<set $CountBackpack = $CountBackpack + 5>><<replace #qtypickup>>You pick up 5 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 6>><<link " Six">><<set $HealthPotions = $HealthPotions + 6>><<set $CountBackpack = $CountBackpack + 6>><<replace #qtypickup>>You pick up 6 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 7>><<link " Seven">><<set $HealthPotions = $HealthPotions + 7>><<set $CountBackpack = $CountBackpack + 7>><<replace #qtypickup>>You pick up 7 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 8>><<link " Eight">><<set $HealthPotions = $HealthPotions + 8>><<set $CountBackpack = $CountBackpack + 8>><<replace #qtypickup>>You pick up 8 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
</span><</nobr>>
<<case "Health Potion">>
<<nobr>>
<<set _freespace = 8 - $CountBackpack>>
<<if $founditem[1] <= _freespace>>
<<set $HealthPotions = $HealthPotions + $founditem[1]>>You now have $HealthPotions Health Potions.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>
<<elseif $founditem[1] > _freespace>>
You don't have room for that many items. Do you want to...Drop some of the items you are carrying?
<span id="dropitems1">
<<if $MealOfLaumspur > 0>>How many Meals of Laumspur do you want to drop?
<<if $MealOfLaumspur >= 1>><<link " One">><<set $MealOfLaumspur = $MealOfLaumspur - 1>><<set $CountBackpack = $CountBackpack - 1>><<replace #dropitems1>>You drop 1 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 2>><<link " Two">><<set $MealOfLaumspur = $MealOfLaumspur - 2>><<set $CountBackpack = $CountBackpack - 2>><<replace #dropitems1>>You drop 2 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 3>><<link " Three">><<set $MealOfLaumspur = $MealOfLaumspur - 3>><<set $CountBackpack = $CountBackpack - 3>><<replace #dropitems1>>You drop 3 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 4>><<link " Four">><<set $MealOfLaumspur = $MealOfLaumspur - 4>><<set $CountBackpack = $CountBackpack - 4>><<replace #dropitems1>>You drop 4 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 5>><<link " Five">><<set $MealOfLaumspur = $MealOfLaumspur - 5>><<set $CountBackpack = $CountBackpack - 5>><<replace #dropitems1>>You drop 5 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 6>><<link " Six">><<set $MealOfLaumspur = $MealOfLaumspur - 6>><<set $CountBackpack = $CountBackpack - 6>><<replace #dropitems1>>You drop 6 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 7>><<link " Seven">><<set $MealOfLaumspur = $MealOfLaumspur - 7>><<set $CountBackpack = $CountBackpack - 7>><<replace #dropitems1>>You drop 7 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 8>><<link " Eight">><<set $MealOfLaumspur = $MealOfLaumspur - 8>><<set $CountBackpack = $CountBackpack - 8>><<replace #dropitems1>>You drop 8 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
</span>
<span id="dropitems2">
<<if $StrengthPotion > 0>>How many Strength Potions do you want to drop?
<<if $StrengthPotion >= 1>><<link " One">><<set $StrengthPotion = $StrengthPotion - 1>><<set $CountBackpack = $CountBackpack - 1>><<replace #dropitems2>>You drop 1 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 2>><<link " Two">><<set $StrengthPotion = $StrengthPotion - 2>><<set $CountBackpack = $CountBackpack - 2>><<replace #dropitems2>>You drop 2 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 3>><<link " Three">><<set $StrengthPotion = $StrengthPotion - 3>><<set $CountBackpack = $CountBackpack - 3>><<replace #dropitems2>>You drop 3 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 4>><<link " Four">><<set $StrengthPotion = $StrengthPotion - 4>><<set $CountBackpack = $CountBackpack - 4>><<replace #dropitems2>>You drop 4 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 5>><<link " Five">><<set $StrengthPotion = $StrengthPotion - 5>><<set $CountBackpack = $CountBackpack - 5>><<replace #dropitems2>>You drop 5 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 6>><<link " Six">><<set $StrengthPotion = $StrengthPotion - 6>><<set $CountBackpack = $CountBackpack - 6>><<replace #dropitems2>>You drop 6 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 7>><<link " Seven">><<set $StrengthPotion = $StrengthPotion - 7>><<set $CountBackpack = $CountBackpack - 7>><<replace #dropitems2>>You drop 7 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>
<<if $StrengthPotion >= 8>><<link " Eight">><<set $StrengthPotion = $StrengthPotion - 8>><<set $CountBackpack = $CountBackpack - 8>><<replace #dropitems2>>You drop 8 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<</if>><</if>></span>
<span id="qtypickup">Do you want to pick up only some of the Health Potions?
<<if _freespace >= 1>><<link " One">><<set $HealthPotions = $HealthPotions + 1>><<set $CountBackpack = $CountBackpack + 1>><<replace #qtypickup>>You pick up 1 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 2>><<link " Two">><<set $HealthPotions = $HealthPotions + 2>><<set $CountBackpack = $CountBackpack + 2>><<replace #qtypickup>>You pick up 2 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 3>><<link " Three">><<set $HealthPotions = $HealthPotions + 3>><<set $CountBackpack = $CountBackpack + 3>><<replace #qtypickup>>You pick up 3 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 4>><<link " Four">><<set $HealthPotions = $HealthPotions + 4>><<set $CountBackpack = $CountBackpack + 4>><<replace #qtypickup>>You pick up 4 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 5>><<link " Five">><<set $HealthPotions = $HealthPotions + 5>><<set $CountBackpack = $CountBackpack + 5>><<replace #qtypickup>>You pick up 5 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 6>><<link " Six">><<set $HealthPotions = $HealthPotions + 6>><<set $CountBackpack = $CountBackpack + 6>><<replace #qtypickup>>You pick up 6 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 7>><<link " Seven">><<set $HealthPotions = $HealthPotions + 7>><<set $CountBackpack = $CountBackpack + 7>><<replace #qtypickup>>You pick up 7 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 8>><<link " Eight">><<set $HealthPotions = $HealthPotions + 8>><<set $CountBackpack = $CountBackpack + 8>><<replace #qtypickup>>You pick up 8 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
</span><</nobr>>
<<case "Health Potion">>
<<nobr>>
<<set _freespace = 8 - $CountBackpack>>
<<if $founditem[1] <= _freespace>>
<<set $HealthPotions = $HealthPotions + $founditem[1]>>You now have $HealthPotions Health Potions.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>
<<elseif $founditem[1] > _freespace>>
You don't have room for that many items. Do you want to...Drop some of the items you are carrying?
<span id="dropitems1">
<<if $MealOfLaumspur > 0>>How many Meals of Laumspur do you want to drop?
<<if $MealOfLaumspur >= 1>><<link " One">><<set $MealOfLaumspur = $MealOfLaumspur - 1>><<set $CountBackpack = $CountBackpack - 1>><<replace #dropitems1>>You drop 1 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 2>><<link " Two">><<set $MealOfLaumspur = $MealOfLaumspur - 2>><<set $CountBackpack = $CountBackpack - 2>><<replace #dropitems1>>You drop 2 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 3>><<link " Three">><<set $MealOfLaumspur = $MealOfLaumspur - 3>><<set $CountBackpack = $CountBackpack - 3>><<replace #dropitems1>>You drop 3 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 4>><<link " Four">><<set $MealOfLaumspur = $MealOfLaumspur - 4>><<set $CountBackpack = $CountBackpack - 4>><<replace #dropitems1>>You drop 4 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 5>><<link " Five">><<set $MealOfLaumspur = $MealOfLaumspur - 5>><<set $CountBackpack = $CountBackpack - 5>><<replace #dropitems1>>You drop 5 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 6>><<link " Six">><<set $MealOfLaumspur = $MealOfLaumspur - 6>><<set $CountBackpack = $CountBackpack - 6>><<replace #dropitems1>>You drop 6 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 7>><<link " Seven">><<set $MealOfLaumspur = $MealOfLaumspur - 7>><<set $CountBackpack = $CountBackpack - 7>><<replace #dropitems1>>You drop 7 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 8>><<link " Eight">><<set $MealOfLaumspur = $MealOfLaumspur - 8>><<set $CountBackpack = $CountBackpack - 8>><<replace #dropitems1>>You drop 8 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
</span>
<span id="dropitems2">
<<if $StrengthPotion > 0>>How many Strength Potions do you want to drop?
<<if $StrengthPotion >= 1>><<link " One">><<set $StrengthPotion = $StrengthPotion - 1>><<set $CountBackpack = $CountBackpack - 1>><<replace #dropitems2>>You drop 1 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 2>><<link " Two">><<set $StrengthPotion = $StrengthPotion - 2>><<set $CountBackpack = $CountBackpack - 2>><<replace #dropitems2>>You drop 2 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 3>><<link " Three">><<set $StrengthPotion = $StrengthPotion - 3>><<set $CountBackpack = $CountBackpack - 3>><<replace #dropitems2>>You drop 3 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 4>><<link " Four">><<set $StrengthPotion = $StrengthPotion - 4>><<set $CountBackpack = $CountBackpack - 4>><<replace #dropitems2>>You drop 4 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 5>><<link " Five">><<set $StrengthPotion = $StrengthPotion - 5>><<set $CountBackpack = $CountBackpack - 5>><<replace #dropitems2>>You drop 5 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 6>><<link " Six">><<set $StrengthPotion = $StrengthPotion - 6>><<set $CountBackpack = $CountBackpack - 6>><<replace #dropitems2>>You drop 6 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 7>><<link " Seven">><<set $StrengthPotion = $StrengthPotion - 7>><<set $CountBackpack = $CountBackpack - 7>><<replace #dropitems2>>You drop 7 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>
<<if $StrengthPotion >= 8>><<link " Eight">><<set $StrengthPotion = $StrengthPotion - 8>><<set $CountBackpack = $CountBackpack - 8>><<replace #dropitems2>>You drop 8 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<</if>><</if>></span>
<span id="qtypickup">Do you want to pick up only some of the Health Potions?
<<if _freespace >= 1>><<link " One">><<set $HealthPotions = $HealthPotions + 1>><<set $CountBackpack = $CountBackpack + 1>><<replace #qtypickup>>You pick up 1 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 2>><<link " Two">><<set $HealthPotions = $HealthPotions + 2>><<set $CountBackpack = $CountBackpack + 2>><<replace #qtypickup>>You pick up 2 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 3>><<link " Three">><<set $HealthPotions = $HealthPotions + 3>><<set $CountBackpack = $CountBackpack + 3>><<replace #qtypickup>>You pick up 3 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 4>><<link " Four">><<set $HealthPotions = $HealthPotions + 4>><<set $CountBackpack = $CountBackpack + 4>><<replace #qtypickup>>You pick up 4 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 5>><<link " Five">><<set $HealthPotions = $HealthPotions + 5>><<set $CountBackpack = $CountBackpack + 5>><<replace #qtypickup>>You pick up 5 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 6>><<link " Six">><<set $HealthPotions = $HealthPotions + 6>><<set $CountBackpack = $CountBackpack + 6>><<replace #qtypickup>>You pick up 6 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 7>><<link " Seven">><<set $HealthPotions = $HealthPotions + 7>><<set $CountBackpack = $CountBackpack + 7>><<replace #qtypickup>>You pick up 7 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 8>><<link " Eight">><<set $HealthPotions = $HealthPotions + 8>><<set $CountBackpack = $CountBackpack + 8>><<replace #qtypickup>>You pick up 8 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
</span><</nobr>>
<<case "Health Potion">>
<<nobr>>
<<set _freespace = 8 - $CountBackpack>>
<<if $founditem[1] <= _freespace>>
<<set $HealthPotions = $HealthPotions + $founditem[1]>>You now have $HealthPotions Health Potions.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>
<<elseif $founditem[1] > _freespace>>
You don't have room for that many items. Do you want to...Drop some of the items you are carrying?
<span id="dropitems1">
<<if $MealOfLaumspur > 0>>How many Meals of Laumspur do you want to drop?
<<if $MealOfLaumspur >= 1>><<link " One">><<set $MealOfLaumspur = $MealOfLaumspur - 1>><<set $CountBackpack = $CountBackpack - 1>><<replace #dropitems1>>You drop 1 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 2>><<link " Two">><<set $MealOfLaumspur = $MealOfLaumspur - 2>><<set $CountBackpack = $CountBackpack - 2>><<replace #dropitems1>>You drop 2 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 3>><<link " Three">><<set $MealOfLaumspur = $MealOfLaumspur - 3>><<set $CountBackpack = $CountBackpack - 3>><<replace #dropitems1>>You drop 3 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 4>><<link " Four">><<set $MealOfLaumspur = $MealOfLaumspur - 4>><<set $CountBackpack = $CountBackpack - 4>><<replace #dropitems1>>You drop 4 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 5>><<link " Five">><<set $MealOfLaumspur = $MealOfLaumspur - 5>><<set $CountBackpack = $CountBackpack - 5>><<replace #dropitems1>>You drop 5 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 6>><<link " Six">><<set $MealOfLaumspur = $MealOfLaumspur - 6>><<set $CountBackpack = $CountBackpack - 6>><<replace #dropitems1>>You drop 6 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 7>><<link " Seven">><<set $MealOfLaumspur = $MealOfLaumspur - 7>><<set $CountBackpack = $CountBackpack - 7>><<replace #dropitems1>>You drop 7 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $MealOfLaumspur >= 8>><<link " Eight">><<set $MealOfLaumspur = $MealOfLaumspur - 8>><<set $CountBackpack = $CountBackpack - 8>><<replace #dropitems1>>You drop 8 Meals of Laumspur. You now have _freespace spaces available.<</replace>><</link>><</if>>
</span>
<span id="dropitems2">
<<if $StrengthPotion > 0>>How many Strength Potions do you want to drop?
<<if $StrengthPotion >= 1>><<link " One">><<set $StrengthPotion = $StrengthPotion - 1>><<set $CountBackpack = $CountBackpack - 1>><<replace #dropitems2>>You drop 1 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 2>><<link " Two">><<set $StrengthPotion = $StrengthPotion - 2>><<set $CountBackpack = $CountBackpack - 2>><<replace #dropitems2>>You drop 2 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 3>><<link " Three">><<set $StrengthPotion = $StrengthPotion - 3>><<set $CountBackpack = $CountBackpack - 3>><<replace #dropitems2>>You drop 3 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 4>><<link " Four">><<set $StrengthPotion = $StrengthPotion - 4>><<set $CountBackpack = $CountBackpack - 4>><<replace #dropitems2>>You drop 4 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 5>><<link " Five">><<set $StrengthPotion = $StrengthPotion - 5>><<set $CountBackpack = $CountBackpack - 5>><<replace #dropitems2>>You drop 5 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 6>><<link " Six">><<set $StrengthPotion = $StrengthPotion - 6>><<set $CountBackpack = $CountBackpack - 6>><<replace #dropitems2>>You drop 6 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if $StrengthPotion >= 7>><<link " Seven">><<set $StrengthPotion = $StrengthPotion - 7>><<set $CountBackpack = $CountBackpack - 7>><<replace #dropitems2>>You drop 7 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>
<<if $StrengthPotion >= 8>><<link " Eight">><<set $StrengthPotion = $StrengthPotion - 8>><<set $CountBackpack = $CountBackpack - 8>><<replace #dropitems2>>You drop 8 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<</if>><</if>></span>
<span id="qtypickup">Do you want to pick up only some of the Health Potions?
<<if _freespace >= 1>><<link " One">><<set $HealthPotions = $HealthPotions + 1>><<set $CountBackpack = $CountBackpack + 1>><<replace #qtypickup>>You pick up 1 Health Potion. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 2>><<link " Two">><<set $HealthPotions = $HealthPotions + 2>><<set $CountBackpack = $CountBackpack + 2>><<replace #qtypickup>>You pick up 2 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 3>><<link " Three">><<set $HealthPotions = $HealthPotions + 3>><<set $CountBackpack = $CountBackpack + 3>><<replace #qtypickup>>You pick up 3 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 4>><<link " Four">><<set $HealthPotions = $HealthPotions + 4>><<set $CountBackpack = $CountBackpack + 4>><<replace #qtypickup>>You pick up 4 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 5>><<link " Five">><<set $HealthPotions = $HealthPotions + 5>><<set $CountBackpack = $CountBackpack + 5>><<replace #qtypickup>>You pick up 5 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 6>><<link " Six">><<set $HealthPotions = $HealthPotions + 6>><<set $CountBackpack = $CountBackpack + 6>><<replace #qtypickup>>You pick up 6 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 7>><<link " Seven">><<set $HealthPotions = $HealthPotions + 7>><<set $CountBackpack = $CountBackpack + 7>><<replace #qtypickup>>You pick up 7 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
<<if _freespace >= 8>><<link " Eight">><<set $HealthPotions = $HealthPotions + 8>><<set $CountBackpack = $CountBackpack + 8>><<replace #qtypickup>>You pick up 8 Health Potions. You now have _freespace spaces available.<</replace>><</link>><</if>>
</span><</nobr>>
<</switch>>
<<return "Go Back">>
O. M. G.
I have written several hundred lines of code so far (well, written a part then copied and modified the rest). I'm not done yet, since everything after the weapons doesn't actually work (well, some of it does). All for about 16 items in the game.
This is not working.
Or, to be more accurate, the problem comes from the fact that it is working, but in the slowest, most akward, cumbersome, time-consuming way possible. I'm working way too hard at implimenting something so simple. Granted, I have added some features that I don't really need (not sure just how much weapon and backpack item-swapping the player is likely to do - there isn't really that much stuff in the book I'm converting). Still, I want to work on these extra features to learn how to do them, and to make something that I (and maybe even others) can use to write their own games (game-stories?) around.
So as much as the OCD part of me wants to keep tinkering with the code I've been working on, I really need to step back and find a better way to write this.
What do you get when you widget?
A <<widget>> is a way to use the normal SugarCube macros and expressions and all that stuff we've already been using - but give it it's own name and call it as if it was a macro. It's a great way to re-use code instead of copying out the long, painful way like I have been doing.Here's an example. Let's say we have 2 Weapons, a Dagger and an Axe. We find another Axe. We decide we want to pick it up, so our $Axes goes up to 2, and our Dagger goes down to 0. We now have 2 Axes and 0 Daggers.
Right now, I have the lines of code that handle all this. For a Dagger, then I had to copy all that code, change a few variables, and paste it into the Axe, then I had to copy all that code, change a few variables, and paste it into the other 7 weapons. Instead, I should have made 1 block of code, as a widget, and just pass the argument of what weapon I'm picking up. Here's the code...
<<widget "GetHandItem">>You already have a $args[0]! Do you want to drop your other weapon and have 2 $args[0]s instead?
<<linkreplace " Yes">>
<<if $args[0] == "Dagger">> <<set $Daggers = 2>> <<elseif $Daggers == 1>> <<set $Daggers = 0>> <</if>>
<<if $args[0] == "Spear">> <<set $Spears = 2>> <<elseif $Spears == 1>> <<set $Spears = 0>> <</if>>
<<if $args[0] == "Mace">> <<set $Maces = 2>> <<elseif $Maces == 1>> <<set $Maces = 0>> <</if>>
<<if $args[0] == "ShortSword">> <<set $ShortSwords = 2>> <<elseif $ShortSwords == 1>> <<set $ShortSwords = 0>> <</if>>
<<if $args[0] == "Warhammer">> <<set $Warhammers = 2>> <<elseif $Warhammers == 1>> <<set $Warhammers = 0>> <</if>>
<<if $args[0] == "Sword">> <<set $Swords = 2>> <<elseif $Swords == 1>> <<set $Swords = 0>> <</if>>
<<if $args[0] == "Axe">> <<set $Axes = 2>> <<elseif $Axes == 1>> <<set $Axes = 0>> <</if>>
<<if $args[0] == "Quarterstaff">> <<set $Quarterstaffs = 2>> <<elseif $Quarterstaffs == 1>> <<set $Quarterstaffs = 0>> <</if>>
<<if $args[0] == "Broadsword">> <<set $Broadswords = 2>> <<elseif $Broadswords == 1>> <<set $Broadswords = 0>> <</if>>
You now have 2 $args[0]s. <<return "Go Back">>
<</linkreplace>>
<<linkreplace " No">> <<return "You leave the item.">>
<</linkreplace>>
<</widget>>
<<linkreplace " Yes">>
<<if $args[0] == "Dagger">> <<set $Daggers = 2>> <<elseif $Daggers == 1>> <<set $Daggers = 0>> <</if>>
<<if $args[0] == "Spear">> <<set $Spears = 2>> <<elseif $Spears == 1>> <<set $Spears = 0>> <</if>>
<<if $args[0] == "Mace">> <<set $Maces = 2>> <<elseif $Maces == 1>> <<set $Maces = 0>> <</if>>
<<if $args[0] == "ShortSword">> <<set $ShortSwords = 2>> <<elseif $ShortSwords == 1>> <<set $ShortSwords = 0>> <</if>>
<<if $args[0] == "Warhammer">> <<set $Warhammers = 2>> <<elseif $Warhammers == 1>> <<set $Warhammers = 0>> <</if>>
<<if $args[0] == "Sword">> <<set $Swords = 2>> <<elseif $Swords == 1>> <<set $Swords = 0>> <</if>>
<<if $args[0] == "Axe">> <<set $Axes = 2>> <<elseif $Axes == 1>> <<set $Axes = 0>> <</if>>
<<if $args[0] == "Quarterstaff">> <<set $Quarterstaffs = 2>> <<elseif $Quarterstaffs == 1>> <<set $Quarterstaffs = 0>> <</if>>
<<if $args[0] == "Broadsword">> <<set $Broadswords = 2>> <<elseif $Broadswords == 1>> <<set $Broadswords = 0>> <</if>>
You now have 2 $args[0]s. <<return "Go Back">>
<</linkreplace>>
<<linkreplace " No">> <<return "You leave the item.">>
<</linkreplace>>
<</widget>>
To call the widget I just pass the argument of what item I am picking up. What's an "argument" I hear you ask? Well, basically it's any extra information that a macro (or widget (or function)) needs to do it's job. Looks like this...
<<GetHandItem "Axe", "Axes", 1>><<GetHandItem is the name, “Axe” “Axes” and 1 are all arguments. Arguments get stored in an array called $args, which the widget can use to look up the info it needs (in this case, the name of the weapon and it's quantity). And remember that arrays start at 0, so $args[0] = “Axe”, $args[1]= “Axes” and $args[2] = 1.So with our new widget, we call it and tell it what weapon we are picking up a second of. Since we can only have 2 weapons total, it goes through all 9 types and increases the one we piced up to 2 while decreasing any others to 0. And, now we can use this one widget instead of copying all the code for all 9 weapon types like before.
To use our widget, we just have to define it somewhere. According to the SugarCube documentation it should be a Passage with the tag “widget”. In the Twee notation I've been using, tags come after the Passage name-
: : PassageName [tags]
passage contents
funny thing though, when I made a new Passage to initialize my variables and set the tag to “widget” I got an error trying to load the Passage...
I had to put the tag in upper-case, “Widget”, for it to work...
Go figure.
Okay, so now that I have one widget to do one part of my giant, ugly pile of steaming code, I need to see what else I can turn into a widget to cut down on the code bloat.
One easy thing to convert to a widget is our “Change Gold” Passage. We were including it to change the amount of gold the player had, but we could also just define it as a widget, like this...
<<widget AddRemGold>> <<nobr>>/*
* This widget will change the player's amount of gold crowns
* [variable: $Gold] to a maximum of 50 and a minimum of 0.
* Usage: <<AddRemGold add/rem #>> the first argument is
* weather to add or remove the amount in the second argument.
*/
<<if $args[0] == "add">>
<<linkreplace "You see $args[1] Gold Crowns.">>
You pick up $args[1] Gold Crowns,
<<set $Gold = $Gold + $args[1]>>
<<if $Gold > 50>>
<<set $Gold = 50>>
but your Belt Pouch only holds 50 Gold Crowns,
<</if>>
you now have $Gold Gold Crowns.
<</linkreplace>>
<<elseif $args[0] == "rem">>
<<linkreplace "You lose $args[1] Gold Crowns.">>
You have lost $args[1] Gold Crowns,
<<set $Gold = $Gold - $args[1]>>
<<if $Gold < 0>> <<set $Gold = 0>> <</if>>
you now have $Gold Gold Crowns.
<</linkreplace>>
<<else>> There has been an error in calling this widget! The first argument must be //add// to increase gold or //rem// to decrease gold!
<</if>> <</nobr>> <</widget>>Now, the code here is basically the same from the Passage. One benefit is that this widget gets rid of the “You lost -10 Gold” output that the Passage had. You'll notice 2 sections in bold though. At the top, I added some comments (in the <<nobr>> so they don't spawn a bunch of blanklines) to explain how the widget works - again, what seems clear now/ to me may not later/ to someone else. And at the bottom I have some “error catching” code- the forst argument has to be “add” or “rem” for the widget to work right, if it isn't then that last <<else>> will print an error message. Also, typing //word// will put that word in italics...
Do I need an error message in my widget? I doubt it, but it doesn't hurt to always look out for errors and figure either how to prevent them or catch them - which really matters when you're writing your own widgets and code that Twine/ SugarCube's built-in editor might not know how to look for. It's like writing comments, not exacly essential to make your game work but can help with keeping it running.
So now I have 2 widgets that I created myself, re-usable bits of code to help simplify my inventory system. They are similar to using a Passage to store code, both give you a way to call one block of code from anywhere in your story and not have to re-type your work. Both are very helpful ideas to keep in mind when designing the mechanics for your game. But while working on these, I realize I need to ask myself something...
Occam's Programming Question: “Am I Over-Complicating This?”
While working on my inventory system I have been looking at all the objects in my game: the gold, 2 armors, 9 weapons and 4 backpack items (ignoring the special items for the moment, will get to them in a second). Those have to go into one of several containers: belt pouch, worn head/ body armor, 2 weapons, 8 backpack items. My code has been tracking each item, and fitting it into the appropriate slot.What if I reversed that?
Instead of having each variable I'm tracking be an item, what if my variables were the slots themselves?
I say that because of the Special Items- in the book they do not take up any slots, you never have more than one, and you never drop or lose them. So I was waiting to talk about them for last, because I already know how to handle them - like Disciplines, with a blank array. I'll just drop them into an array, test for them when I need them, and ignore them the rest of the time. Very simple. Going over all this code though, really the helmet and chainmail waistcoat are special items too, so I can kind of forget about them.
One of my biggest hurdles has been stuffing 9 weapons into 2 slots - so why not just have 2 variables, $weapon1 and $weapon2, and just say what weapon is in each? That gives me 2 things to check for instead of 9. Backpack items stink because while there are only 4 of them, you can have multiples of each (up to 8 total) - that's been kind of hard to track what is where. Again though, why not just make variables for $backpack1 to $backpack8, then I can just count down the list?
I'll explore that idea next episode...
Subscribe to:
Posts (Atom)



















