0 votes
by (980 points)
Okay within my inventory system I want to be able to have them click read, eat, or drink next to items and it go to a read, eat, or drink passage. Within the passage I want it to where <<if>> lastclick was ____ then apply these stats. For exampel:

Inventory System Looks like:

<<for $i = 0; $i < $inventory.length; $i++>>
<<set $item = $inventory[$i]>>
<<print $item.Name>><<if $item.Type eq "Book">> [[Read]] <<print $item.Description>>
<</for>>

Example of Displayed item

Book of Beginnings [[Read]]- Book on life so far.

 

Another way I tried it

Inventory System Looks like:

<<for $i = 0; $i < $inventory.length; $i++>>
<<set $item = $inventory[$i]>>
<<if $item.Type eq "Book">> [[$item.Name]] - <<print $item.Description>>

<<else>><<print $item.Name>>  -  <<print $item.Description>>

<</if>>

<</for>>

Example of Displayed item

[[Book of Beginnings]]- Book on life so far.

 

 

Read Passage

<<if lastClicked == "Book of Beginnings">>

It is believed that the Gods created the different sentient races... but a new belief has arrived. One that threatens the existance of the Gods. But regardless of these beliefs, life goes on for the common folk. High Elves learning magic in the universities, dark elves holding public debates, gnomes hiding in caves... ETC

 

Or something along those lines. It does not have to say of course last clicked. I tried having $item.Name as the link instead of Read. But it creates a passage called $item.Name and displays the Books name. If I left the $item.Name passage as it was and tried putting information in it and base that off of what items they had... then it would only display the last book within the inventory. Then if I delete that $item.Name passage and create "Book of Beginnings" passage. The link for that book would go there and if I had another Book and created a passage for it, it's linkwould go there... but then that means for every readable book I would have a different passage.

 

Am I making any sense? lol I do not always do well at explaining myself.

1 Answer

+1 vote
by (63.1k points)
edited by

You want to use either the link markup with a setter component or the <<link>> macro.  You'll also need to use the <<capture>> macro since you'll need to capture a changing value (of the temporary variable _i) for use in asynchronous code (the setter component or content of the <<link>>).  For example:

<<for _i, _item range $inventory>>
<<capture _i>><<nobr>>
<<print _item.Name>>
<<switch _item.Type>>
<<case "Book">>[[Read][$itemIdx to _i]]
<<case "Food">>[[Eat][$itemIdx to _i]]
<<case "Drink">>[[Drink][$itemIdx to _i]]
<</switch>>
- <<print _item.Description>>
<</nobr>><</capture>>
<</for>>

Usage within the action passages (i.e. Read, Eat, Drink), assume this is Read:

You just read the <<print $inventory[$itemIdx].Name>>.

 

PS: Please don't place the compiler and story format information solely into the subject/title, that's what tags are for.

by (980 points)
That worked for the read, drink, and eat. 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, since I want to check first to see if something it equipped it 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>>
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.
...