Quantcast
Channel: Twine Forum
Viewing all articles
Browse latest Browse all 3830

Setter Link broken inside for loop for SugarCube 2

$
0
0
While building an inventory system I ran into an interesting problem:
''Wearing''
* top: //<<= clothes[PC.top].name>>// [[inspect][$inspected_item = PC.top]]
* bottom: //<<= clothes[PC.bot].name>>// [[inspect][$inspected_item = PC.bot]]
* shoes: //<<= clothes[PC.shoes].name>>// [[inspect][$inspected_item = PC.shoes]]
<<for $i = 0; $i < PC.acc.length; ++$i>>\
* accessory: //<<= clothes[PC.acc[$i]].name>>// [[inspect][$inspected_item = PC.acc[$i]]]
<</for>>\

''Backpack (aka your servant)''
<<for $i = 0; $i < PC.back.length; ++$i>>\
<<if clothes.hasOwnProperty(PC.back[$i])>>\
* (<<= clothes[PC.back[$i]].loc>>) //<<= clothes[PC.back[$i]].name>>// <<= $i>> <<= PC.back[$i]>> [[inspect][$inspected_item = PC.back[$i]]]
<</if>>\
<</for>>\

Here I'm using a "temporary" variable $inspected_item as a way to pass a parameter into the "inspect" passage.
The inspect passage is:
$inspected_item
<<if clothes.hasOwnProperty($inspected_item)>>\
<<= clothes[$inspected_item].longdesc.capitalizeFirstLetter()>>
<<endif>>\
clothes is a global lookup table mapping strings to Clothing objects, which have longdesc as a property.

The setter links work as intended for the non-loop portions, but when it gets to the backpack - tested with
PC.back = ["test_top", "test_bot"]
the inventory page works normally:
// ...proper non-loop stuff
Backpack (aka your servant)
(top) test top 0 test_top inspect
(bot) test bot 1 test_bot inspect
but when I click on inspect, it seems the $inspected_item has not been set:
$inspected_item
Both the loop counter and the value I want to set to have the proper value before the link setter, so it points to the link setter as the problem here. Any ideas on what might be wrong or a better way of doing what I'm trying to do?

Viewing all articles
Browse latest Browse all 3830

Trending Articles