Howdy, Stranger!

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

Direction Menu

I have a working direction menu which stores the directions and locations in the passage tags:
(set: $tagDir to (a: (passage:)'s tags))
(if: not(($tagDir[0][1]) is "X" or it is ""))[(print: "↑"+"[["+$tagDir[0][1]+"]]")]
etc.

And it works, as long as I create an entry for every direction in order, otherwise ...

If there isn't an "X" or a location name it complains: an empty variable isn't the same type of data as the string "]]"

My tags will only allow one "X" so that didn't work, so I was wondering if there was a simple way in the (if:) line that I'm missing?

Comments

  • edited September 2015
    I can see now why this probably wont work in the way I'm expecting. There are no 'empty' strings for a start, and no array beyond what is read in from the tags.

    I wanted to detect when there was an end to the locations in the tags. I can do that with a symbol if I need to, but maybe I need to change the way I'm implement the locations.

    Maybe something like this -

    tags - "hut","↓","parlour","→","garden"
    (set: $tagDir to (a: (passage:)'s tags))
    (set: $l to $l +2) <!-- step 2 to account for symbol -->
    (unless: $l >=15 or ($tagDir[0][$l]) is "X")[
    (print: $tagDir[0][$l]+"[["+$tagDir[0][$l+1]+"]]")]
    

    Of course that doesn't quite work either. I could do an array at the start, but I may yet add or change some locations.
  • I created the following four passage test and noticed a couple of things:
    (note: I am using Twee notation, lines starting with :: indicate a new passage, the :: is followed by the passage name, and any tags are contained within square brackets)
    :: No Tags
    (display: "Test")
    [[One Tag]]
    
    :: One Tag [a]
    (display: "Test")
    [[Two Tags]]
    
    :: Two Tags [a b]
    (display: "Test")
    
    :: Test
    {(set: $tags to (passage:)'s tags)
    (set: $tagDir to (a: $tags))}
    Passage: (print: (passage:)'s name)
    tags: len: (print: $tags's length) val: |(print: (passage:)'s tags)|
    dir: len: (print: $tagDir's length) val: |(print: $tagDir)|
    

    a. Based on the output of No Tags the (passage:)'s tags seems to be returns an array which always has at least one element, which seems to be an empty string if there were no tags.

    b. The (set: $tagDir to (a: $tags)) line in my example (equal to the (set: $tagDir to (a: (passage:)'s tags)) line in your example) is creating the equivalent of a two dimensional array (an outer array in which each item is an array)

    So based on this and the fact your direction tags appear to come in pairs I would first wrap your logic in a conditional something like the following:
    (set: $tags to (passage:)'s tags)
    (if: $tags's length != 1)[
    There appears to be some tags, lets process them
    ]
    
  • That fixed it!

    :: Directions [start test1 test2 test3]
    (set: $tags to (passage:)'s tags)
    (set: $l to $l + 1)(print: $tags[$l])
    (unless: $l >= $tags's length -1)[(display: "Directions")]
    

    Thanks again for your help.
  • edited October 2015
    In the end I set up an array of locations:
    (set: $location to (a:))
    (set: $locationList to $location.push(
    (a: "","","","",),
    (a: "Hut Front Room","N","Hut Tool Room","Tool Room","S","Hut Bedroom","Bedroom"),
    (a: "Hut Tool Room","","","","S","Hut Front Room","Parlour"),
    (a: "Hut Bedroom","N","Hut Front Room","Parlour")))
    

    I put a room number in each tag: 1, 2, 3, etc.

    & An Exits passage that appears in my sidebar:
    {(if: ($location[$locNum][1]) is "N")[(print: "↑" + "[[" + ($location[$locNum][3]) + "|" + ($location[$locNum][2]) + "]]")<br></br>]
    (if: ($location[$locNum][4]) is "S")[(print: "↓" + "[[" + ($location[$locNum][6]) + "|" + ($location[$locNum][5]) + "]]")<br></br>]
    

    This works well.
Sign In or Register to comment.