Howdy, Stranger!

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

Problems with if statement

Yes, I did a search, and read the other posts, but mine is a bit different and I could not apply those answers to my story.
I'm trying to create a page where some of the text changes depending on previous decisions the player made. Say, if they chose to be an elf or a dwarf.
This is what is not working: after all, you are <<if $race = elf>> an elf <<else>> a dwarf <<endif>>

Is there a comprehensive guide to Harlowe I can use? Getting bits and subtle hints after half an hour of searching, and then having to ask in a forum, is not what I want to spend my whole day in.

Comments

  • edited June 2015
    Harlowe documentation is here: http://twine2.neocities.org/

    Twine 2 general documentation is here: http://twinery.org/wiki/twine2:guide. Running through the tutorial under "Learning Twine 2" will help a bunch with understanding basic syntax.

    As far as I know, Harlowe doesn't use the <<foo>> syntax.

    Syntax looks something like this:
    After all, you are (if: $race is "elf")[ an elf.](else:)[ a dwarf.]
    

    Have fun!
  • edited June 2015
    It is still giving me trouble. No matter what I choose, it shows up as "an elf" when I play.
  • Try this:

    (set: $race to "dwarf")
    After all, you are (if: $race is "elf")[ an elf.](else:)[ a dwarf.]

    I GUARANTEE you it will work.
  • edited June 2015
    Rafe wrote: »
    It is still giving me trouble. No matter what I choose, it shows up as "an elf" when I play.
    What does the code look like where you are initializing the $race variable?

  • Dominia wrote: »
    Rafe wrote: »
    It is still giving me trouble. No matter what I choose, it shows up as "an elf" when I play.

    What does the code look like where you are initializing the $race variable?

    I'm making a test game to avoid something horrible to happen to my main one. So the variables will be different.
    Setting the variable, page 1:
    (set: $sx to "neither")
    (link: "I'm a baby boy")[(set: $sx to "boy")(goto: "Name")]
    (link: "I'm a baby girl")[(set: $sx to "girl")(goto: "Name")]

    using them in page 2:
    What's your name, (if: $sx = boy)[mr](else:)[miss]?
  • change the = to == or eq
  • edited June 2015
    Rafe wrote: »
    What's your name, (if: $sx = boy)[mr](else:)[miss]?
    Looks like you're missing quotes around the word 'boy'. Also, the single equals sign (=) basically assigns boy (without quotes) to the $sx variable. So you're overwriting the %sx variable in that statement instead of doing a comparison. Try using 'is' instead.
    What's your name, (if: $sx is "boy")[mr](else:)[miss]?
    
  • Sage wrote: »
    change the = to == or eq

    I have another question, related to this. Do I make another thread, or ask here?
  • You can use the same thread instead of spawning another one.
  • Ha! Or spamming one!
    ;)
  • edited June 2015
    It is possible for twine to remember what did it select from an "either" random variable, so it can be used later?
    Let's say I want a creature to have a random colour from a list (which I know how to do), but later, I want it to generate loot based on that colour: namely, red paint for red creatures, yellow for yellow ones, etc., so the character can paint their house later. (I will try inventory management later, but feel free to give me tips if you want to, I'm writing down everything)
  • edited June 2015
    Yes that is possible. The easiest way is to set a variable to recall later. Do you know how to do that?
    $redLoot = 0
    $greenLoot =1
    $yellowLoot =1
    $purpleLoot = 0
    $blueLoot=0
    
    In Harlowe (set:)
    In SugarCube <<>>
    
    For a random variable
    <<set $random = Math.ceil(Math.random()*10)>>
    <<print $random>>
    <<set $foo = $random>>
    <<print $random>>
    
    (thanks to @Sharpe for the last one)
  • edited June 2015
    My answer assumes you are using (either:) to pick the color like you said and if statements to select the creature and later on the loot. Datamaps are something you may want to look into but they are a bit more advanced. Best to understand the basics first.

    Just select the color and assign it to a variable each time you want to create a mob and it's associated loot.

    You can do something like this:
    (set: $baseColor to (either: "red", "blue", "green"))
    (if: $baseColor is "red")[(set: $monsterType to "Red Dragon")(set: $monsterLoot to "Red Wristguards")]
    (elseif: $baseColor is "blue")[(set: $monsterType to "Blue Meanie")(set: $monsterLoot to "Blue Beanie")]
    (else:)[(set: $monsterType to "Green Goblin")(set: $monsterLoot to "Green Gauntlets")]
    

    You don't have to set the loot at the same time as the mob type. I just dumped it all together as an example. Also, at some point @L said he was going to allow multiple variables in a (set:) like in Twine 1.x but I am not sure those have been implemented yet.
  • as I was told before, I set variables with: (set: $variable1 to "value0")
    So to store a random variable I set them, and then... what?
    I tried this, but neither works, they just give me the value0 thingie

    [(set: $variable1 to "value0")(either: "value1", "value2", "value3")]
    (set: $variable1 to "value0")[(either: "value1", "value2", "value3")]
    (set: $variable1 to "value0")(either: "value1", "value2", "value3")
  • edited June 2015
    The example I provided uses (set:) with (either:).

    The (set:) in your code ends at the first closed parenthesis so the (either:) does nothing which is why you are only getting 'the value0 thingie'. :)
  • (set: $variable1 to either: "value1", "value2", "value3") gives me the "unexpected token" error
    Same with (set: $variable1 to [either: "value1", "value2", "value3"])
  • edited June 2015
    Look at my example:
    (set: $baseColor to (either: "red", "blue", "green"))
    
    Parentheses matter. Don't panic. You'll get it.
  • Dominia wrote: »
    Look at my example

    That actually solved it. I just did not know where to put double () or add [] instead
  • Excellent. Whenever you need any additional help, just post here. There's usually someone on to assist. We have a pretty solid community here. I've learned a bunch from them. Good luck with the project!
  • Thank you, Dominia.

    Into to next question, I'm obsessed with trying complicated things in my story. Right now, is letting the player read the page text, and waiting for them to click a word to show them the prompt to define their own feratures, like eye color. Not very relevant to plot, but I feel this will help them "bond" with their character (the story requires they actually care)


    Here is the monster I created. It is not reanimating!
    (set: $eyecolor to "noeyes")
    (if: $eyecolor is "noeyes")(link: "What color are you eyes?")[(put: (prompt: "My eye color is...") into $eyecolor)]
  • Uhm, can't edit the previous message. If instead of that, I wanted the prompt to appear only after the player clicks on a word, how would I do it? I'm a bit scared of timed variables, so I will not try that.

    I tried adding a prompt to [page text]<c1, but it did not work
  • edited June 2015
    These really WOULD BE better in their own thread so that other people can learn from each separate question. If you don't, that means people that know will have to keep answering the same questions again.

    In this case, however, I can answer this one.

    You are super close to the answer. Instead of Page Text, you can put the name of a passage and then it will show up that way.
    My text will add|here>[...]
    (click-replace: ?here)[(display: "New Passage")]
    
  • edited June 2015
    @Sage: A simple search on prompt: will pull pull up this thread. So the info will be fully available. Most of the time when a newbie asks a question, the title of the thread isn't really what they are actually asking about since they don't yet really know what they are asking about. That's why @klembot suggests they do a search prior to asking a question. Because of that I don't think it's that big of a deal that he puts his answers in a single thread but ymmv. Definitely something I don't care enough about either way to belabor it.

    Anyway ...
    From here on is for @Rafe not @Sage so there's no misunderstanding.

    Harlowe doesn't yet have a way to do what you are asking without some additional javascript added to your story.

    See http://twinery.org/forum/discussion/comment/6468/

    One workaround without having to do the above javascript hack is to change the way you are displaying your passages.

    Source passage:
    (set: $eyecolor to "noeyes")
    (if: $eyecolor is "noeyes")[["What color are your eyes?"|prompt_passage]]
    

    Target passage (named prompt_passage for this example):
    (set: $eyecolor to (prompt: "My eye color is..."))
    Your eye color is $eyecolor.
    
    (link-goto: "CONTINUE", (history:)'s last)
    

    Of course, you don't have to send them back to the prior passage. I just don't know enough about what you're doing in your passage to know how to end it.

    (Out for the evening.)
  • edited June 2015
    @Dominia
    Sorry... I disagree. Not about the new post thing, do whatever you want...

    But the code I posted DOES work. I am currently using it in a published story

    There is a chance I didn't understand the question... but the code does work. Where do you think I went wrong?

    EDIT: I HAVE NO ADDED JAVASCRIPT
  • edited June 2015
    @Sage: What are you talking about? I didn't say you went wrong anywhere. My comment to you was about the spawning new threads issue, which isn't a big deal. The rest of the message i.e. code was in response to @Rafe's question. At no point did I say your code didn't work.

    There I edited it so you can see my intended meaning. I didn't even look at or try your code so have no idea what it does or doesn't do. K?
  • @Dominia

    No... I totally get that. I was able to tell which one you were addressing. I was saying that the code I posted, I think, does what he needs it to. I should have used the QUOTE thingy, but I was saying I disagree with the part where it says Harlowe can't do that. I disagreed because I was making it work.

    I asked you, at the end of it, where I went wrong because I know you are a better coder than I am. My code works though, so I was wondering where you were saying Harlowe can't.

    Anyway, sorry for any confusion.
    :)
  • @Sage: I thought his original question about (prompt:) was him wanting the prompt to be inline like <<textinput>> in SugarCane, <<textarea>> and <<textbox>> in SugarCube for1.x, so was still fixated on him getting his prompt to set a $variable without interrupting the storyflow too much. Not even sure if that's what he was still going for.

    The click-replace you suggested is one of the things I really like about Harlowe, btw.

    And as for coding, I'm still a n00b when it comes to Twine. I've seen some of your responses in other threads, you're understanding is pretty good, buddy! Now I really need to go out. It's Saturday night!
  • @Dominia

    REALLY!!!????

    haha- thank you! I've been trying.

    :)
Sign In or Register to comment.