0 votes
by (490 points)

Okay, I'm back (most of the year later) with another probably stupid question. This one's for an interactive word crawl I'm working on (series of writing challenges).

I have an array. I call it $TrackingWords. This array contains numerous strings that get added as the player/writer gets through different challenges in the story.

I want the contents of this array to be able to be printed at the player/writer's whim so the end result looks like this:

1) Entrance Exam - 673
2) Arrival on Herabeth - 48
3) Torgerutt Tam - 179

How do I accomplish this? I keep spawning errors trying to figure it out on my own. (I give myself credit for making it this far; be glad my earlier struggle just to get my strings working and saved somewhere is over.)

2 Answers

+1 vote
by (159k points)
selected by
Best answer

As well as Deadshot's solution you could use the (for:) macro to loop through each element within the Array.

Assuming that you have an Array something like the following...

(set: $list to (a: "Entrance Exam - 673", "Arrival on Herabeth - 48", "Torgerutt Tam - 179"))\

...then you could use code like the following to print an unordered list.

**Unordered List**
(if: $list's length > 0)[\
(for: each _item, ...$list)[_item<br>]

... or if you prefer an ordered list then you can use the (range:) macro to generate the indexes of that list like so

**Ordered List**
(if: $list's length > 0)[\
(for: each _index, ...(range: 1, $list's length))[_index) (print: $list's (_index))<br>]

warning: You will of noticed that the last two examples both used an (if:) macro to test the length of the Array before calling the (for:) macro, this is because the (for:) macro throws an error if the Array is empty.

by (490 points)
Thank you! This was what I was looking for!


(Also, as a random FYI, each entire string consists of "#) Challenge Descriptor - #words".)
0 votes
by (6.2k points)
(set: $trackingWords to (a: 'Hi', 'hello', 'wassup!'))
(print: $trackingWords's 1st)
(print: $trackingWords's 2nd)
(print: $trackingWords's 3rd)



by (490 points)
edited by

I appreciate the attempt to help, but as the $TrackingWords array will eventually have 100+ objects in it even on the short side, I really didn't want to have to add a line of code for every potential task the player/writer will complete. That was the entire point behind setting up the array.

The strings inside are generated by the following code:

(text: ...(a: $Task, ") ", $Task_Descriptor, " - ", $Task_Words))

$Task is automatically updated to (it + 1) to track what happened in what order, $Task_Descriptor is (set:) every time another challenge comes along, and $Task_Words is the player's input.

So all of those variables get updated every time the button is hit to report a task result, and the resulting string gets added to the array. Part of this was also because there are a lot of cases were tasks can be done in vastly different orders, and part of it was so I didn't have to try to guess everything or add a bajillion variables.

Case in point: Old version had over 50 variables and I only had 32 passages. Maybe 3 challenges. Most of it was character building stuff.

New version isn't even half as far as the old version yet, but it's still sitting at only about 10 variables and I'm not going to have to add more until I get up toward where I left off previously.


(Sorry for the ramble. I'm awake again and brevity is not one of my greatest skills.)