Data name in an array problem

I am trying to create something, where if the player has a rifle, they can continue, and if they don’t, they will die.
The error says that they can’t find data names in the array.
I am new to harlowe code, and twine in general, so sorry if it is formatted badly.
It also has a typewriter effect, and that might be contributing to the problem.

(if:$rifle is true) 
[(set: $typewriterTextm to "A beast leaps out of the bushes, and you react immediatly, blasting it in the head." )]
{
    (set: $typewriterPosm to 1)
    |typewriterOutput1>[]
    (live: 20ms)[
        (append: ?typewriterOutput1)[(print: $typewriterTextm's $typewriterPosm)]
        (set: $typewriterPosm to it + 1)
        (if: $typewriterPosm is $typewriterTextm's length + 1)[
            (stop:)
        ]
    ]
}

[[Walk down the path->Forested Path]]
(unless:$rifle is true)
[(set: $typewriterTextm to "A beast leaps out of the bushes, and mauls you to death." )]
{
    (set: $typewriterPosm to 1)
    |typewriterOutput1>[]
    (live: 20ms)[
        (append: ?typewriterOutput1)[(print: $typewriterTextm's $typewriterPosm)]
        (set: $typewriterPosm to it + 1)
        (if: $typewriterPosm is $typewriterTextm's length + 1)[
            (stop:)
        ]
    ]
}
2 Likes

I’m no good with Harlowe, so I’m not going to be able to help you. Sorry. However, I just wanted to give you some tips on how to get help faster.

First off , you should post this in the Twine category, not general. And also give it a Harlowe tag for clarity, although that’s not critical. But at least mention it in your title if you’re not going to tag it.

Second, you should describe what is going wrong. I literally have no idea what you need help with because you never described your problem. A simple “I’m trying to get it to do this but it’s doing this instead” is fine. And if it’s giving an error message, post that too.

Another thing is you should use the code formatting option for your code before posting (there’s a button for it above the post editor). It’ll make stuff like this:
function() {
if (a == 1)
dostuff();
}
}
look like this:

function() {
	if (a == 1)
		dostuff();
	} 
}

Your code is nearly impossible to read in its current state.

Anyway, I’m not trying to sound like a jerk. But I feel most people would just ignore a post if it were presented as yours currently is.

1 Like

I actually figured out the problem. :smiley: I had to learn a bit of Harlowe to do it. Heh.

Anyway, your problem is that you were placing the closing brackets for your if and unless statements in the wrong spots. This code works.

(if:$rifle is true)[
    (set: $typewriterTextm to "A beast leaps out of the bushes, and you react immediatly, blasting it in the head." )
    {
        (set: $typewriterPosm to 1)
        |typewriterOutput1>[]
        (live: 20ms)[
            (append: ?typewriterOutput1)[(print: $typewriterTextm's $typewriterPosm)]
            (set: $typewriterPosm to it + 1)
            (if: $typewriterPosm is $typewriterTextm's length + 1)[
                (stop:)
            ]
        ]
    }

    [[Walk down the path->Forested Path]]
]

(unless:$rifle is true)[
    (set: $typewriterTextm to "A beast leaps out of the bushes, and mauls you to death." )
    {
        (set: $typewriterPosm to 1)
        |typewriterOutput1>[]
        (live: 20ms)[
            (append: ?typewriterOutput1)[(print: $typewriterTextm's $typewriterPosm)]
            (set: $typewriterPosm to it + 1)
            (if: $typewriterPosm is $typewriterTextm's length + 1)[
                (stop:)
            ]
        ]
    }
]

However, if I could make a suggestion: I think your code would look a lot cleaner and it’d be a lot less typing if you put your typewriter stuff in a separate passage since it looks like you plan on using it for all your text.

I would do it something like this:

This is your example passage. Notice how I cleaned up the conditions (if x is true followed immediately by unless x is true is redundant. else serves the same purpose). Also the display command will include the contents of typewriter into this passage. We’ll move the typewriter stuff to that passage.

(if:$rifle is true)[
    (set: $typewriterTextm to "A beast leaps out of the bushes, and you react immediatly, blasting it in the head." )
    (display: "typewriter")

    [[Walk down the path->Forested Path]]
]
(else:)[
    (set: $typewriterTextm to "A beast leaps out of the bushes, and mauls you to death." )
    (display: "typewriter")
]

This is the typewriter passage:

{
    (set: $typewriterPosm to 1)
    |typewriterOutput1>[]
    (live: 20ms)[
        (append: ?typewriterOutput1)[(print: $typewriterTextm's $typewriterPosm)]
        (set: $typewriterPosm to it + 1)
        (if: $typewriterPosm is $typewriterTextm's length + 1)[
            (stop:)
	  ]
    ]
}

That’s much easier to read and reuse and works exactly the same. :slight_smile:

2 Likes

@tayruh and @Kodex

As explained within the String data documentation (and Array data documentation) whenever you use an expression to access a specific character of a String value (or a specific element of an Array)

(print: $typewriterTextm's $typewriterPosm)

… you should place that expression within parenthesise.

(print: $typewriterTextm's ($typewriterPosm) )

Is that just for clarity? Because it seems to work just fine without them.

Thanks!

I updaded my post to make it look better and easier to read. Thanks for the help though

No.

The expression you use to determine either the position index or property name/key can be more complex than just just retrieving the current value of a single variable…

(print: $string's ($number - 1) )
(print: $string's ( ($number * $multiplier) - 1) )
(print: $array's ($array's length) )
(print: $datamap's ("row:" + (str: $x) + ",col:" + (str: $y)) )

…so parenthesise are used to enforce that the position index or property name/key expression is evaluated before the result is used, and to ensure the order in which the sub-parts of an expression ar evaluated in.

eg. for the above (print: $string's ( ($number * $multiplier) - 1) ) example we want the multiplication ($number * $multiplier) sub-expression to be evaluated before subtracting one from the result.