+1 vote
asked by (980 points)
edited by
In another question post I asked about read, drink, and eat. That system worked. I had a different system for my equipment... It will line up the equip and unequip next to the name and description. But it only want to equip and unequip the last item stats and remove links from those before it. I need the if statements... I could not figure out a way to use switch and case for the equipment with an if statement, since I want to check first to see if something is equipped and if that item is currently equipped. If the item is equipped then have a unequiped option. I have tried many versions to attempt to get it to work. Below under Equipment Passage is one attempt and is the most recent.

 

StoryInit (only parts that pertain to equipment)

<<set $equipment = []>>
 <<set $head = {
    "Wearing" : false,
    "Type" : "head",
    }>>
<<set $neck = {
    "Wearing" : false,
    "Type": "neck",
    }>>
<<set $back = {
    "Wearing" : false,
    "Type": "back",
    }>>
<<set $backpack = {
    "Wearing" : false,
    "Type": "backpack",
    }>>    
<<set $mainHand = {
    "Wearing" : false,
    "Type": "mainhand",
    }>>
<<set $offHand = {
    "Wearing" : false,
    "Type": "offhand",
    }>>
<<set $armor = {
    "Wearing" : false,
    "Type": "armor",
    }>>    
<<set $belt = {
    "Wearing" : false,
    "Type": "belt",
    }>>
<<set $gloves = {
    "Wearing" : false,
    "Type": "gloves",
    }>>
<<set $legs = {
    "Wearing" : false,
    "Type": "legs",
    }>>
<<set $feet = {
    "Wearing" : false,
    "Type": "feet",
    }>>
<<set $ring = {
    "Wearing" : false,
    "Type": "finger",
    }>>

<<set $necklace1 = {
  "Name" : "Amulet of Lineage",
  "Type" : "necklace",
  "idName": "necklace1",
  "Place" : "neck",
  "hasItem" : false,
  "hasEquip" : false,
  "Strength" : 0,
  "Intelligence": 0,
  "Constitution" : 0,
  "Dexterity" : 0,
  "Defense" : 2,
  "Charisma" : 0,
  "Description" : "Any decendant has a necklace that is a claim to their bloodline. This one has a symbol of a falcon's head."
}>>

<<set $necklace2 = {
  "Name" : "Quartz Crystal Necklace",
  "Type" : "necklace",
  "idName": "necklace2",
  "Place" : "neck",
  "hasItem" : false,
  "hasEquip" : false,
  "Strength" : 0,
  "Intelligence": 2,
  "Constitution" : 0,
  "Dexterity" : 0,
  "Defense" : 0,
  "Charisma" : 0,
  "Description" : "For clarity of mind."
    }>>
    
<<set $necklace3 = {
  "Name" : "Lucky Rabbit Foot Necklace",
  "Type" : "necklace",
  "Place" : "neck",
  "hasItem" : false,
  "hasEquip" : false,
  "Strength" : 0,
  "Intelligence": 0,
  "Constitution" : 0,
  "Dexterity" : 2,
  "Defense" : 0,
  "Charisma" : 0,
  "Description" : "Most humans believe that a rabbit's foot brings good luck."
    }>>
    
<<set $necklace4 = {
  "Name" : "Amulet of Carnage",
  "Type" : "necklace",
  "Place" : "neck",
  "hasItem" : false,
  "hasEquip" : false,
  "Strength" : 2,
  "Intelligence": 0,
  "Constitution" : 0,
  "Dexterity" : 0,
  "Defense" : 0,
  "Charisma" : 0,
  "Description" : "Only through battle can an Orc earn this trophy."
    }>>
    
<<set $ring1 = {
  "Name" : "Grounding Stone Ring",
  "Type" : "ring",
  "Place" : "finger",
  "hasItem" : false,
  "hasEquip" : false,
  "Strength" : 0,
  "Intelligence": 1,
  "Constitution" : 0,
  "Dexterity" : 0,
  "Defense" : 1,
  "Charisma" : 0,
  "Description" : "A stone that helps it's user to keep calm"
    }>>

 

Equipment Passage

[[return|$return]]
<<for $e = 0; $e < $equipment.length; $e++>>
<<set $gear = $equipment[$e]>>
<<print $gear.Name>>
<<print $gear.Description>>
<<capture $e>><<nobr>>

<<if ($neck.Wearing eq false) and ($gear.Place eq $neck.Type)>> <<link [[Equip][$gearIdx to $e]]>><<set $str += $gear.Strength>> <<set $int += $gear.Intelligence>> <<set $con += $gear.Constitution>> <<set $dex += $gear.Dexterity>> <<set $def += $gear.Defense>> <<set $char += $gear.Charisma>> <<set $gear.hasEquip = true>> <<set $neck.Wearing = true>> <</link>>

<<elseif ($ring.Wearing eq false) and ($gear.Place eq $ring.Type)>> <<link [[Equip][$gearIdx to $e]]>><<set $str += $gear.Strength>> <<set $int += $gear.Intelligence>> <<set $con += $gear.Constitution>> <<set $dex += $gear.Dexterity>> <<set $def += $gear.Defense>> <<set $char += $gear.Charisma>> <<set $gear.hasEquip = true>> <<set $ring.Wearing = true>> <</link>>

<<elseif ($gear.hasEquip == true)>>Equipped <<link [[UnEquip][$gearIdx to $e]]>> <<set $str -= $gear.Strength>> <<set $int -= $gear.Intelligence>> <<set $con -= $gear.Constitution>> <<set $dex -= $gear.Dexterity>> <<set $def -= $gear.Defense>> <<set $char -= $gear.Charisma>> <<set $gear.hasEquip = false>><<set $neck.Wearing = false>>  <</link>>

<<elseif ($gear.hasEquip == true)>>Equipped <<link [[UnEquip][$gearIdx to $e]]>> <<set $str -= $gear.Strength>> <<set $int -= $gear.Intelligence>> <<set $con -= $gear.Constitution>> <<set $dex -= $gear.Dexterity>> <<set $def -= $gear.Defense>> <<set $char -= $gear.Charisma>> <<set $gear.hasEquip = false>><<set $ring.Wearing = false>>  <</link>>
<</if>>
<</nobr>><</capture>>
<</for>>

1 Answer

0 votes
answered by (980 points)
Just FYI to any that want to use a similar Equip/Unequip system:

Equipment Passage:

[[return|$return]]
Equipment
Neck: <<print $neck.Name>>
Ring: <<print $ring.Name>>

<<for _e, $gear range $equipment>>

<<print $gear.Name>>
<<print $gear.Description>>
<<nobr>><<if $gear.Strength gt 0>> Strength + $gear.Strength <</if>>
<<if $gear.Intelligence gt 0>> Intelligence + $gear.Intelligence <</if>>
<<if $gear.Constitution gt 0>> Constitution + $gear.Constitution <</if>>
<<if $gear.Dexterity gt 0>> Dexterity + $gear.Dexterity <</if>>
<<if $gear.Defense gt 0>> Defense + $gear.Defense <</if>>
<<if $gear.Charisma gt 0>> Charisma + $gear.Charisma <</if>>
<</nobr>>
<<nobr>>
<<capture _e>>
<<switch $gear.Type>>
<<case "necklace">>[[Options|Neck][$gearIdx to _e]]
<<case "ring">>[[Options|Ring][$gearIdx to _e]]
<</switch>>
<</capture>>
<</nobr>>
<</for>>
 

Neck Passage

<<return>>
<<print $equipment [$gearIdx].Name>>

    <<if ($neck.Wearing eq false) and ($equipment[$gearIdx].Place eq $neck.Type)>> <<link [[Equip|Equipment]]>><<set $str +=             $equipment [$gearIdx].Strength>> <<set $int += $equipment [$gearIdx].Intelligence>> <<set $con += $equipment [$gearIdx].Constitution>> <<set $dex += $equipment [$gearIdx].Dexterity>> <<set $def += $equipment [$gearIdx].Defense>> <<set $char += $equipment [$gearIdx].Charisma>> <<set $gear.hasEquip = true>> <<set $neck.Wearing = true>> <<set $neck.Name = $equipment[$gearIdx].Name>> <</link>>

    <<elseif ($neck.Wearing eq true) and ($neck.Name neq $equipment[$gearIdx].Name)>> Please remove equipped necklace.

    <<elseif ($equipment [$gearIdx].Name eq $neck.Name)>>
    Equipped <<link [[UnEquip|Equipment]]>>
    <<set $str -= $equipment [$gearIdx].Strength>> <<set $int -= $equipment [$gearIdx].Intelligence>> <<set $con -= $equipment [$gearIdx].Constitution>> <<set $dex -= $equipment [$gearIdx].Dexterity>> <<set $def -= $equipment [$gearIdx].Defense>> <<set $char -= $equipment [$gearIdx].Charisma>> <<set $gear.hasEquip = false>><<set $neck.Wearing = false>> <<set $neck.Name = "None">> <</link>>

<</if>>

 

Ring Passage //repeat of neck put with $ring for parts

<<return>>
<<print $equipment[$gearIdx].Name>>

<<if ($ring.Wearing eq false) and ($equipment[$gearIdx].Place eq $ring.Type)>> <<link [[Equip|Equipment]]>><<set $str += $equipment [$gearIdx].Strength>> <<set $int += $equipment [$gearIdx].Intelligence>> <<set $con += $equipment [$gearIdx].Constitution>> <<set $dex += $gear.Dexterity>> <<set $def += $equipment [$gearIdx].Defense>> <<set $char += $equipment [$gearIdx].Charisma>> <<set $gear.hasEquip = true>> <<set $ring.Wearing = true>> <<set $ring.Name = $gear.Name>> <</link>>

    <<elseif ($ring.Wearing eq true) and ($ring.Name neq $equipment[$gearIdx].Name)>> Please remove equipped ring.

    <<elseif ($equipment[$gearIdx].Name eq $ring.Name)>>  Equipped <<link [[UnEquip|Equipment]]>> <<set $str -= $equipment [$gearIdx].Strength>> <<set $int -= $equipment [$gearIdx].Intelligence>> <<set $con -= $equipment [$gearIdx].Constitution>> <<set $dex -= $equipment [$gearIdx].Dexterity>> <<set $def -= $equipment [$gearIdx].Defense>> <<set $char -= $equipment [$gearIdx].Charisma>> <<set $gear.hasEquip = false>><<set $ring.Wearing = false>> <<set $ring.Name = "None">> <</link>>    
    
<</if>>

 

 

It is not 'pretty' but it works! :D
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...