0 votes
by (250 points)

I've set up a couple of characters:-

<<set $char1 to {name: "Bob", gender: "Male"}>>
<<set $char2 to {name: "Dave", gender: "Male"}>>
<<set $allcharacters to [$char1, $char2]>>

I want to create links on a page for each character, then when the user clicks the link know which character they picked and display some info (kind of like a bio).

<<for $i=0; $i < $allchars.length; $i++>>
	[[$allchars[$i].name->CharacterBio][$item = $allchars[$i]]]

So then on the next passage I tried:-

<<print $item.name>>

But I get a undefined error, so I assume that it isn't been created, and I'm not understanding how to create the links on the previous passage.

Am I on the right lines, or am I trying to do this by some complicated method, when there is an easier way?

1 Answer

0 votes
by (63.1k points)
selected by
Best answer

Are you aware that your variables $allcharacters and $allchars have different names? Also, $i should probably be temporary. You will probably also need to capture that variable. 

I suggest something like: 

<<for _i = 0; _i < $allcharacters.length; _i++>>
    <<capture _i>>
        <<link $allcharacters[_i].name "Character Bio">>
            <<set $item = $allcharacters[_i]>>

Warning: untested. 

by (250 points)
Yeah sorry I was retyping the stuff and just got allchars / allcharacters mixed up in my brain, they are the same in the code.

I did manage to get it working using a print macro, but your code is better.