Howdy, Stranger!

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

Harlowe String Compare

Hi. Please help me out. I have a set a variable $hypothesis to a string that is created at runtime in the story. Is there a way to compare a string against the variable or specifically look for word or phrase within the string?

Example: (set: $hypothesis to "Sugar, Spice, Everything Nice and Chemical X")
(if: $hypothesis is ""Sugar, Spice, Everything Nice and Chemical X")[Powerpuff Girls!]
(else-if: $hypothesis contains "Chemical X)[You die in an explosion]
(else:)[Nothing happens]

When I use this nothing by the last else is returned. Help please.

Comments

  • I might have figured it out. To do a string compare use ' ' instead of " ".
  • edited October 2016
    It does not matter if you use single or double quotes to define a String literal, they both result in the same value. As demonstrated by the following example:
    Are single and double quoted String literals equal: \
    (if: "abcde" is 'abcde')[Yes](else:)[No]
    

    There are a couple syntax errors in your example, you have an extra double quote at the start of the String literal in your (if:) macro and you are missing a double quote at the end of the String literal in your (else-if:) macro. Try the following:
    (set: $hypothesis to "Sugar, Spice, Everything Nice and Chemical X")
    (if: $hypothesis is "Sugar, Spice, Everything Nice and Chemical X")[Powerpuff Girls!]
    (else-if: $hypothesis contains "Chemical X")[You die in an explosion]
    (else:)[Nothing happens]
    
Sign In or Register to comment.