Howdy, Stranger!

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

[harlowe] Bad at math, or harlowe's fail?

I have this passage.
{
(if: $loverace is "human" or it is "half ogre")[(set: $loveagemodifier to 1)]

(elseif: $loverace is "dwarf")[(set: $loveagemodifier to 5)]

(elseif: $loverace is "elf" or it is "dark elf")[(set: $loveagemodifier to 10)]

(elseif: $loverace is "half elf")[(set: $loveagemodifier to 1.75)]

(elseif: $loverace is "gnome")[(set: $loveagemodifier to 4.5)]

(elseif: $loverace is "halfling")[(set: $loveagemodifier to 2.5)]

(elseif: $loverace is "half orc")[(set: $loveagemodifier to 0.75)]

(set: $loveage to (round: ($pcage / (($pcagemodifier / $loveagemodifier) + ((random: 90,110) * 0.01)))))
}

It's supposed to grab a certain age modifier from both the player and the love interest, depending on their races, ad or substract a random percentage (10% in this case), and apply the equation to translate the player's age into a apropriate age for the love interest. (aka, no 45 years old man courting a teenage elf)

I'm just this bad at math, that I can't spot the mistake I probably made yesterday due to lack of sleep. Can you help me?

Comments

  • Rafe wrote: »
    I have this passage.
    {
    (if: $loverace is "human" or it is "half ogre")[(set: $loveagemodifier to 1)]
    
    (elseif: $loverace is "dwarf")[(set: $loveagemodifier to 5)]
    
    (elseif: $loverace is "elf" or it is "dark elf")[(set: $loveagemodifier to 10)]
    
    (elseif: $loverace is "half elf")[(set: $loveagemodifier to 1.75)]
    
    (elseif: $loverace is "gnome")[(set: $loveagemodifier to 4.5)]
    
    (elseif: $loverace is "halfling")[(set: $loveagemodifier to 2.5)]
    
    (elseif: $loverace is "half orc")[(set: $loveagemodifier to 0.75)]
    
    (set: $loveage to (round: ($pcage / (($pcagemodifier / $loveagemodifier) + ((random: 90,110) * 0.01)))))
    }
    

    It's supposed to grab a certain age modifier from both the player and the love interest, depending on their races, ad or substract a random percentage (10% in this case), and apply the equation to translate the player's age into a apropriate age for the love interest. (aka, no 45 years old man courting a teenage elf)

    I'm just this bad at math, that I can't spot the mistake I probably made yesterday due to lack of sleep. Can you help me?

    You barely provided any information so I had to some guess work and created an sample example that works you can edit and improve it:
    First create one passage as so:
    (set: $pcage to 1500)
    (link:"human")[(set:$pcrace to "human")]
    (if: $pcrace is "human" or it is "half ogre")[(set: $pcagemodifier to 1)]
    
    (elseif: $pcrace is "dwarf")[(set: $pcagemodifier to 5)]
    
    (elseif: $pcrace is "elf" or it is "dark elf")[(set: $pcagemodifier to 10)]
    
    (elseif: $pcrace is "half elf")[(set: $pcagemodifier to 1.75)]
    
    (elseif: $pcrace is "gnome")[(set: $pcagemodifier to 4.5)]
    
    (elseif: $pcrace is "halfling")[(set: $pcagemodifier to 2.5)]
    
    (elseif: $pcrace is "half orc")[(set: $pcagemodifier to 0.75)]
    (link:"half orc")[(set:$loverace to "half orc")]
    [[Lover's age->Untitled Passage]]
    
    then create another one like this
    (if: $loverace is "human" or it is "half ogre")[(set: $loveagemodifier to 1)]
    
    (elseif: $loverace is "dwarf")[(set: $loveagemodifier to 5)]
    
    (elseif: $loverace is "elf" or it is "dark elf")[(set: $loveagemodifier to 10)]
    
    (elseif: $loverace is "half elf")[(set: $loveagemodifier to 1.75)]
    
    (elseif: $loverace is "gnome")[(set: $loveagemodifier to 4.5)]
    
    (elseif: $loverace is "halfling")[(set: $loveagemodifier to 2.5)]
    
    (elseif: $loverace is "half orc")[(set: $loveagemodifier to 0.75)]
    
    (set: $loveage to (round: ($pcage / (($pcagemodifier / $loveagemodifier) + ((random: 90,110) * 0.01)))))
    $loveage
    
    You can add more links and edit it to your liking
  • it doesn't work properly. Something is dividing by 0.

    Here are two test passages in which I simplify the process.

    The first one does this, in order: It sets the longevity modifier of the player (at what age it reach different life stages, and the race of the love interest (her longevity autocalculates). It then displays the second passage, which I will explain later.

    The third line multiplies the longevity modifier of the player and a random age I put in there to test it. For different races, their age of independence would be sooner or later than it is for humans.

    And last, a simple "twine, show me your results" along with a link to retry and see what I get next.
    {(set: $pcagemodifier to 1, $loverace to "human")
    
    (display: "second passage")
    
    (set: $pcage to (20 * $pcagemodifier))
    
    }Pc age: $pcage
    $pcagemodifier
    
    Love age: $loveage
    $loveagemodifier
    
    (link: "again")[(goto: "this passage")]
    

    Here you can see the different longevity multiplier of the different races (they have to stay in the. Just at the end of the passage, is that thing I can't solve by myself, because I'm horrible at math.

    In one sentence, the problem is that his equation only generates love interests than are older than the player, never one that is a bit younger. It should generate love interests from 10% younger to 10% older, taking into account their race's longevity.
    {
    (if: $loverace is "human" or it is "half ogre")[(set: $loveagemodifier to 1)]
    
    (elseif: $loverace is "dwarf")[(set: $loveagemodifier to 5)]
    
    (elseif: $loverace is "elf" or it is "dark elf")[(set: $loveagemodifier to 10)]
    
    (elseif: $loverace is "half elf")[(set: $loveagemodifier to 1.75)]
    
    (elseif: $loverace is "gnome")[(set: $loveagemodifier to 4.5)]
    
    (elseif: $loverace is "halfling")[(set: $loveagemodifier to 2.5)]
    
    (elseif: $loverace is "half orc")[(set: $loveagemodifier to 0.75)]
    
    (set: $loveage to ($pcage / (($pcagemodifier / $loveagemodifier)) + ((random: 90,110) * 0.01)))
    }
    

    If I still didn't manage to explain myself, please tell me.
  • Rafe wrote: »
    it doesn't work properly. Something is dividing by 0.

    First you have to press both links the human and the half orc link before seeing lover's age 2nd general advice don't use {} in harlowe just delete it all together, you will see that if you copy paste the two passages I provided they will work perfectly as I have already created and tested them
  • edited September 2016
    Your problem is that your percentage is always a positive value or zero, so when you add it to the original the result can only be equal to or greater than the original.

    The following shows how to randomly get a value that ranges from negative 10 percent to positive 10 percent, which when applied to an age can result in both a higher and lower second age.
    (set: $ageA to 20)
    (set: $percent to ((random: -10, 10) / 100))
    (set: $ageB to $ageA + ($ageA * $percent))
    
    percent: $percent
    age A: $ageA
    age B: $ageB
    
  • greyelf wrote: »
    Your problem is that your percentage is always a positive value or zero, so when you add it to the original the result can only be equal to or greater than the original.

    The following shows how to randomly get a value that ranges from negativity 10 percent to positive 10 percent, which when applied to an age can result in both a higher and lower second age.
    (set: $ageA to 20)
    (set: $percent to ((random: -10, 10) / 100))
    (set: $ageB to $ageA + ($ageA * $percent))
    
    percent: $percent
    age A: $ageA
    age B: $ageB
    

    damn I missed that I was only trying to implement the op's values in a way that it works that's probably why the values are not that different but the problem arises in how input a random age assuming the op wants the user to want to be able to enter their age I tried
    (set: $age to (prompt: "What's your age?"))
    
    but it wouldn't work because it was a string, plus the op should really add more links to choose what race the player and the lover are but I'll assume that the op already did
  • greyelf wrote: »

    Thanks!

    And what about the equation itself, it is correct? It worked differently on excel.
    (set: $loveage to ($pcage / ($pcagemodifier / $loveagemodifier) + ((random: -10,10) / 100)))
    

  • how about this one? It seems to work when I test it in excel, making progresively more diverse results as the character ages.

    (set: $loveage to ($pcage * $pcagemodifier) + ((random: -10,10) * ($pcage / 100)) * $loveagemodifier)
Sign In or Register to comment.