Howdy, Stranger!

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

Harlowe Error with negative numbers?

Hey all,

I'm having trouble getting an if macro to work when a variable is negative.

I'm using the latest version of twine harlowe online, and I have four passages, set up as follows.


Start Passage:
Hello this is a numbers test

do a good thing
do a bad thing

$goodBad

do a good thing:
(set: $goodBad to it +1)

YOU DID GOOD!

next

$goodBad

do a bad thing:
(set: $goodBad to it -1)

YOU DID BAD!

next

$goodBad

next:
(if: $goodBad is > 0)[Yay! Good ending! You are nice.]
(else-if: $goodBad is < 0)[Hee hee! You rascal. You are not nice.]

$goodBad

So the problem is this: if I do a bad thing, $goodBad prints out as "NaN" and so my else-if statement in "next" won't work. Does Twine not do negative numbers anymore? Or what? How do I get a number to go less than zero without printing out as "NaN"?

Thanks in advance for your help. :)

Comments

  • edited July 2017
    First, you should declare your variables before using them. A startup-tagged passage is the best place to do this. Don't rely on Harlowe to set the variable to the right value for you.
    (set: $goodBad to 0)
    

    Second, you shouldn't use the TwineScript strict equality operator 'is' with other comparison operators. Harlowe 2.x let's you get away with this to some extent, but it's still a bad idea.
    Right: 
    (if: $goodBad > 0)[...]
    
    Wrong: 
    (if: $goodBad is > 0)[...]
    

    Third, you don't have any sort of test for if the value remains at zero. It doesn't matter in this scaled-down test, but it might in your game if there are a lot of decisions and its possible the player could conceivably arrive at 0.

    I'm not at my computer to test this out right now, but if you fix the first issue, I suspect that you'll stop seeing NaN. The other second issue should be fixed, but it probably isn't the culprit in this case.

    Also, note that we really prefer version numbers, rather than "the latest version of Twine and Harlowe." I assume that you mean Harlowe 2.0.1 by latest version, but you could also mean "the version of Harlowe that is the default format of the latest version of Twine", which I believe is actually Harlowe 1.2.4. It's just better to grab the numbers.
Sign In or Register to comment.