Howdy, Stranger!

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

[Harlowe] Arrays/Datamaps, creating a timetable

Harlowe, Twine 2. I was hoping someone could help me work through what I'm trying to accomplish. I've read up on arrays and datamaps but don't yet have the full sense of all the possibilities of those two things.

I want to create a train timetable that as the player moves from passage to passage it reduces each train arrival time and when the first reaches zero, it's removed it from the list and a new one is added at the end of the list. Each train has a "time", "color", and a "direction".

I've written the following array that refreshes itself exactly how I'd like but since it's an array it only handles one set of the attributes I want: "time". Ideally the other attributes follow "time" as it counts down.

In a preceding passage I set:
(set: $time to (array: (random: 3,4),(random:6,7),(random:9,10)))

[[Next|test]]

Then this reduces the "time", moves the first index to the end when it reaches 0, and shifts the others down:
(set: $time's 1st -= 1)
(set: $time's 2nd -= 1)
(set: $time's 3rd -= 1)

(if: $time's 1st < 1)[(set: $time's 1st += (random: 9,10))(move: $time's 1st into $time's 4th)]

(print: $time)

[[Refresh|test]]

Datamaps seem the best way to manage the various attributes needed for each train, but as far as I've been able to figure they don't store their data in a particular order like arrays. Therefore I can't shift the indexes in the same way. Any thoughts or ideas?

Comments

  • Here's a way to do this:

    For the setup passage -
    (set: $time to (array: (random: 3,4),(random:6,7),(random:9,10)))
    (set: $train1 to (datamap: "time", $time's 1st, "color", "red", "direction", "south"))
    (set: $train2 to (datamap: "time", $time's 2nd, "color", "green", "direction", "north"))
    (set: $train3 to (datamap: "time", $time's 3rd, "color", "blue", "direction", "west"))
    (print: $time)
    (print: $train1)
    (print: $train2)
    (print: $train3)
    [[Next|test2]]
    

    For the refreshing passage -
    (set: $time's 1st -= 1)
    (set: $time's 2nd -= 1)
    (set: $time's 3rd -= 1)
    (if: $time's 1st < 1)[(set: $time's 1st += (random: 9,10))(move: $time's 1st into $time's 4th)]
    (set: "time" of $train1 to $time's 1st)
    (set: "time" of $train2 to $time's 2nd)
    (set: "time" of $train3 to $time's 3rd)
    (print: $time)
    (print: $train1)
    (print: $train2)
    (print: $train3)
    [[Refresh|test2]]
    
Sign In or Register to comment.