Howdy, Stranger!

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

Determining Turn Order/Highest Number from a group of numbers

edited August 2015 in Help! with 1.x
Hello again! I'm attempting to construct a simple turn based rpg that involves an agility stat.

Monsters and the player can have an agility of between 1-65. That inherent agility is added with a random number between 1-35. Then the higher number gets to act first such as attack or run away. I'm not a math guru so I did something pretty simple.

I've been able to determine the higher number as long as it is only two numbers using a function I've seen in the wiki.
something like if (PlayerAgi >= MonsterAgi) >><stuff>

I don't know how to get the highest number when there are 3 or more agility stats being compared though.
I've been able to generate the random numbers and everything so far, but I don't know how to give twine more than two numbers.

What if its:
PartyMember1/PartyMember2/Monster1/Monster2 and each one has a different value. How do I calculate the order? Do I need to just use a page worth of 1-to-1 comparisons or is there a simpler short hand way? This is SugarCane 1.42.

Comments

  • it's a good idea to give us some code to see. But from the sound of it, I would just put another if loop inside the first.
  • edited August 2015
    Yeah, i made a pretty hue series of nested loops. It's really convoluted and messy and would of been better if it could be placed in something akin to a c++ function.

    Here's the code for anyone having the same issue, though I didn't use generic names and again it's huge:


    <<if $MonsterAgilityTemp >= $JonathanAgilityTemp and $MonsterAgilityTemp >= $ElijahAgilityTemp and $MonsterAgilityTemp >= $MicChreaAgilityTemp >>
    <<set $First = "Monster">>

    <<if $JonathanAgilityTemp >= $ElijahAgilityTemp and $JonathanAgilityTemp >= $MicChreaAgilityTemp>>

    <<set $Second = "Jonathan">>
    <<if $ElijahAgilityTemp >= $MicChreaAgilityTemp>>
    <<set $Third to "Elijah">>
    <<set $Fourth to "Chrea" >>
    <<else if $MicChreaAgilityTemp
    >= $ElijahAgilityTemp>>
    <<set $Third to "Chrea">>
    <<set $Fourth to "Elijah">>
    <<endif>>



    <<else if $ElijahAgilityTemp >= $JonathanAgilityTemp and $ElijahAgilityTemp >= $MicChreaAgilityTemp>>

    <<set $Second = "Elijah">>
    <<if $JonathanAgilityTemp >= $MicChreaAgilityTemp>>
    <<set $Third to "Jonathan">>
    <<set $Fourth to "Chrea">>
    <<else if $MicChreaAgilityTemp
    >= $JonathanAgilityTemp>>
    <<set $Third to "Chrea">>
    <<set $Fourth to "Jonathan">>
    <<endif>>


    <<else if $MicChreaAgilityTemp >= $JonathanAgilityTemp and $MicChreaAgilityTemp >= $ElijahAgilityTemp>>

    <<set $Second = "Chrea">>
    <<if $JonathanAgilityTemp >= $ElijahAgilityTemp>>
    <<set $Third to "Jonathan">>
    <<set $Fourth to "Elijah" >>
    <<else if $ElijahAgilityTemp
    >= $JonathanAgilityTemp>>
    <<set $Third to "Elijah">>
    <<set $Fourth to "Jonathan">>
    <<endif>>
    <<endif>>

    <<elseif $JonathanAgilityTemp >= $MonsterAgilityTemp and $JonathanAgilityTemp >= $ElijahAgilityTemp and $JonathanAgilityTemp >= $MicChreaAgilityTemp >>
    <<set $First = "Jonathan">>

    <<if $MonsterAgilityTemp >= $ElijahAgilityTemp and $MonsterAgilityTemp >= $MicChreaAgilityTemp>>

    <<set $Second = "Monster">>
    <<if $ElijahAgilityTemp >= $MicChreaAgilityTemp>>
    <<set $Third to "Elijah">>
    <<set $Fourth to "Chrea" >>
    <<else if $MicChreaAgilityTemp
    >= $ElijahAgilityTemp>>
    <<set $Third to "Chrea">>
    <<set $Fourth to "Elijah">>
    <<endif>>



    <<else if $ElijahAgilityTemp >= $MonsterAgilityTemp and $ElijahAgilityTemp >= $MicChreaAgilityTemp>>

    <<set $Second = "Elijah">>
    <<if $MonsterAgilityTemp >= $MicChreaAgilityTemp>>
    <<set $Third to "Monster">>
    <<set $Fourth to "Chrea">>
    <<else if $MicChreaAgilityTemp
    >= $MonsterAgilityTemp>>
    <<set $Third to "Chrea">>
    <<set $Fourth to "Monster">>
    <<endif>>


    <<else if $MicChreaAgilityTemp >= $MonsterAgilityTemp and $MicChreaAgilityTemp >= $ElijahAgilityTemp>>

    <<set $Second = "Chrea">>
    <<if $MonsterAgilityTemp >= $ElijahAgilityTemp>>
    <<set $Third to "Monster">>
    <<set $Fourth to "Elijah" >>
    <<else if $ElijahAgilityTemp
    >= $MonsterAgilityTemp>>
    <<set $Third to "Elijah">>
    <<set $Fourth to "Monster">>
    <<endif>>
    <<endif>>


    <<elseif $ElijahAgilityTemp >= $JonathanAgilityTemp and $ElijahAgilityTemp >= $MonsterAgilityTemp and $ElijahAgilityTemp >= $MicChreaAgilityTemp >>
    <<set $First = "Elijah">>

    <<if $JonathanAgilityTemp >= $MonsterAgilityTemp and $JonathanAgilityTemp >= $MicChreaAgilityTemp>>

    <<set $Second = "Jonathan">>
    <<if $MonsterAgilityTemp >= $MicChreaAgilityTemp>>
    <<set $Third to "Monster">>
    <<set $Fourth to "Chrea" >>
    <<else if $MicChreaAgilityTemp
    >= $MonsterAgilityTemp>>
    <<set $Third to "Chrea">>
    <<set $Fourth to "Monster">>
    <<endif>>



    <<else if $MonsterAgilityTemp >= $JonathanAgilityTemp and $MonsterAgilityTemp >= $MicChreaAgilityTemp>>

    <<set $Second = "Monster">>
    <<if $JonathanAgilityTemp >= $MicChreaAgilityTemp>>
    <<set $Third to "Jonathan">>
    <<set $Fourth to "Chrea">>
    <<else if $MicChreaAgilityTemp
    >= $JonathanAgilityTemp>>
    <<set $Third to "Chrea">>
    <<set $Fourth to "Jonathan">>
    <<endif>>


    <<else if $MicChreaAgilityTemp >= $JonathanAgilityTemp and $MicChreaAgilityTemp >= $MonsterAgilityTemp>>

    <<set $Second = "Chrea">>
    <<if $JonathanAgilityTemp >= $MonsterAgilityTemp>>
    <<set $Third to "Jonathan">>
    <<set $Fourth to "Monster" >>
    <<else if $MonsterAgilityTemp
    >= $JonathanAgilityTemp>>
    <<set $Third to "Monster">>
    <<set $Fourth to "Jonathan">>
    <<endif>>
    <<endif>>

    <<elseif $MicChreaAgilityTemp >= $JonathanAgilityTemp and $MicChreaAgilityTemp >= $ElijahAgilityTemp and $MicChreaAgilityTemp >= $MonsterAgilityTemp >>
    <<set $First = "MicChrea">>

    <<if $JonathanAgilityTemp >= $ElijahAgilityTemp and $JonathanAgilityTemp >= $MonsterAgilityTemp>>

    <<set $Second = "Jonathan">>
    <<if $ElijahAgilityTemp >= $MonsterAgilityTemp>>
    <<set $Third to "Elijah">>
    <<set $Fourth to "Monster" >>
    <<else if $MonsterAgilityTemp
    >= $ElijahAgilityTemp>>
    <<set $Third to "Monster">>
    <<set $Fourth to "Elijah">>
    <<endif>>



    <<else if $ElijahAgilityTemp >= $JonathanAgilityTemp and $ElijahAgilityTemp >= $MonsterAgilityTemp>>

    <<set $Second = "Elijah">>
    <<if $JonathanAgilityTemp >= $MonsterAgilityTemp>>
    <<set $Third to "Jonathan">>
    <<set $Fourth to "Monster">>
    <<else if $MonsterAgilityTemp
    >= $JonathanAgilityTemp>>
    <<set $Third to "Monster">>
    <<set $Fourth to "Jonathan">>
    <<endif>>


    <<else if $MonsterAgilityTemp >= $JonathanAgilityTemp and $MonsterAgilityTemp >= $ElijahAgilityTemp>>

    <<set $Second = "Monster">>
    <<if $JonathanAgilityTemp >= $ElijahAgilityTemp>>
    <<set $Third to "Jonathan">>
    <<set $Fourth to "Elijah" >>
    <<else if $ElijahAgilityTemp
    >= $JonathanAgilityTemp>>
    <<set $Third to "Elijah">>
    <<set $Fourth to "Jonathan">>
    <<endif>>
    <<endif>>
    <<endif>>
    <<endsilently>>
  • The simplest thing to do would probably be to use an array (of objects) rather than individual variables. For example, the following will give you an array sorted from highest to lowest initiative:
    <<silently>>
    /% Initialize the $initiative array. %/
    <<set $initiative to []>>
    
    /% Add simple name/initiative pair objects to the array. %/
    <<set $initiative.push({ name : "Monster",  initiative : $MonsterAgilityTemp })>>
    <<set $initiative.push({ name : "Jonathan", initiative : $JonathanAgilityTemp })>>
    <<set $initiative.push({ name : "Elijah",   initiative : $ElijahAgilityTemp })>>
    <<set $initiative.push({ name : "Chrea",    initiative : $MicChreaAgilityTemp })>>
    
    /% Sort the array from highest to lowest initiative. %/
    <<set $initiative.sort(function (a, b) { return b.initiative - a.initiative; })>>
    <<endsilently>>
    

    Afterward, you'd simply index the array (0-based) and name property of the associated object. For example, comparing the old ($First) to new ($initiative[0].name):
    • $First$initiative[0].name
    • $Second$initiative[1].name
    • $Third$initiative[2].name
    • $Fourth$initiative[3].name
Sign In or Register to comment.