Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

array contents as links?

I want to display a list of inventory items (array contents) with each item being a clickable link.

For example, if we did...
<<set #inv = ["cat", "dog", "feather"]>>
...I would like to somehow display within a passage...
[[cat]]
[[dog]]
[[feather]]
...but have it procedurally generated since the contents of the inventory can change depending on the player's actions. Is this possible? More trouble than it's worth? I don't know that my game's going to have a ton of items, so another way I can see doing this is with a series of <<if>> statements, one for each link.

Comments

  • I wanted to do this, too-- turns out it's very simple! Just make your strings the links when you add them to the array.

    So, mine is, <<set $packed to ["[[winter coat]]","[[boots]]"]>> etc.
  • You can also:
    printinvline::
    <<nobr>>
    <<set $ix to parameter(0)>>
    <<if inv.length gt $ix>>
    <<print "[[" + inv[$ix] + "|Examine_" + inv[$ix] + "][$return to passage()]]<br>">>
    <<endif>>
    <<endnobr>>

    printinv::
    Inventory:
    <<nobr>>
    <<printinvline 0>>
    <<printinvline 1>>
    <<printinvline 2>>
    <<printinvline 3>>
    <<printinvline 4>>
    <<printinvline 5>>
    <<printinvline 6>>
    <<printinvline 7>>
    <<endnobr>>
    Be better if we had a loop directive, but you can unroll the loop to cover your maximum inventory size - or write a recursive printer.
  • Thanks! Ends up I haven't had occasion to need to do this yet, but I'm glad I have a way to now. Thanks again.
Sign In or Register to comment.