Howdy, Stranger!

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

Two questions: My set to true variable won't then set to false & approval ratings dictating ifs?

First question: I want my "displayHeader" variable to be set to "false" until I set it to "true" at the beginning of the story. I put "(set: $displayHeader to true)" in my startup passage, in my welcome passage I put "(set: $displayHeader to false)" then in my "begin" passage I put "(set: $displayHeader to true)" but for some reason my header doesn't show up in my welcome (as it is not supposed to) but then still doesn't show up in begin or any passage after that.

Am I doing it wrong?

Second question: I'm working with approval ratings. I want my relationships page to show a simple line that says "Your relationship with [x person] is:" and depending on the approval rating (from 0 = hatred to 100 = love) what it says. So, if Theodore's relationship is 75, I want it to say, "Your relationship with Theodore is: Intimate."

My startup sets approval and relationship to 50 for each character (for now).

My relationships code:
Theodore Approval Rating: $theodoreApproval
Louisa Approval Rating: $louisaApproval
Emma Approval Rating: $emmaApproval

Your relationship with Theodore is: (if: $theodoreRelationship is 50)[friendly](if: $theodoreRelationship <= 40)[tense](if: $theodoreRelationship <= 25)[cold](if: $theodoreRelationship <= 10)[based in mutual hatred](if: $theodoreRelationship <= 60)[friendly](if: $theodoreRelationship <= 75)[flirtatious](if: $theodoreRelationship <= 85)[intimate](if: $theodoreRelationship <= 100)[love]

(link-goto: "Return", (history:)'s last)

Unfortunately, when my Theodore relationship is set to 40, this shows as so:
Inventory | Craft Something | Relationships | Skills

Theodore Approval Rating: 35
Louisa Approval Rating: 50
Emma Approval Rating: 50

Your relationship with Theodore is: tensefriendlyflirtatiousintimatelove

Return

How sexy.

I presume I'm using my greater/less thans wrong (I had it set to less than but it didn't like that at all). What should I do to make this work?

Comments

  • edited September 2015
    There isn't enough information to see why the header isn't working. Attaching a copy of the story might help.

    There are 2 problems with your approval rating code.
    The first is that all the conditions will be checked, regardless of whether they're true or not. You need to use elseif for the later checks.
    The second problem is due to the ordering, if you change to it to elseif, if the value is 10 then it'll print the result for the <= 40 check rather than the <= 10 check.

    The following should do what you want:
    Your relationship with Theodore is: (if: $theodoreRelationship is 50)[friendly]
    (elseif: $theodoreRelationship <= 10)[based in mutual hatred]
    (elseif: $theodoreRelationship <= 25)[cold]
    (elseif: $theodoreRelationship <= 40)[tense]
    (elseif: $theodoreRelationship <= 60)[friendly]
    (elseif: $theodoreRelationship <= 75)[flirtatious]
    (elseif: $theodoreRelationship <= 85)[intimate]
    (elseif: $theodoreRelationship <= 100)[love]
    

    I added extra line breaks for legibility.
  • Thanks for helping with the relationship! I'm gonna try that later.

    I attach a copy of my twine which refuses to header on/off. :)
  • I can see what the problem is now. Twine runs the header before running the actual passage.
    So when it's displaying the "Begin" passage, $displayHeader only gets set to true after it's run the
    (if: $displayHeader is true)
    
    line and decided not to show the header. When I tried it, the header did appear when I got to the "to the door." passage. The easiest fix would be to move the line setting $display header to true to the "Height" passage, then you'll get the header when "Begin" shows.

    BTW since $displayHeader is a true/false value you don't need the is true part of the test. You can just write
    (if: $displayHeader)
    

    Also, in the "you stop to offer him greeting." passage you're trying to increment $theodoreApproval with the line
    (set: $theodoreaApproval + 1)
    
    which doesn't work. You need to do
    (set: $theodoreaApproval to it + 1)
    
  • edited September 2015
    A Harlowe header is processed before the passage currently being displayed is, this means that the result of a variable change in the current passage will not be known about in the displayed header. So if you want the header to know about a variable change you need to make that change in the previous displayed passage.

    To fix this issue in your example move the (set: $displayHeader to true) to the end of your welcome passage.
  • A small amendment to prof_yaffle's solution.

    If you want to leave the extra line breaks in so your code stays more readable then you can use Harlowe's built-in line break removal feature to remove them before the result is shown to the reader/player.
    To do this simply wrap the text/code you want line-breaks removed from in a set of curly brace { } characters.

    A modified version of prof_yaffle's example, note the { character before the (if:) macro and the } character after the last hook:
    Your relationship with Theodore is: {(if: $theodoreRelationship is 50)[friendly]
    (elseif: $theodoreRelationship <= 10)[based in mutual hatred]
    (elseif: $theodoreRelationship <= 25)[cold]
    (elseif: $theodoreRelationship <= 40)[tense]
    (elseif: $theodoreRelationship <= 60)[friendly]
    (elseif: $theodoreRelationship <= 75)[flirtatious]
    (elseif: $theodoreRelationship <= 85)[intimate]
    (elseif: $theodoreRelationship <= 100)[love]}
    

    I added extra line breaks for legibility.[/quote]
Sign In or Register to comment.