Formulas Implemented + Random

thespis721thespis721 Member Posts: 4
edited November -1 in Working with GS (Mac)
Hey guys,

I saw how to add mathematical formulas using the expression editor, however, I have a an implementation question. Let's say I want to have it that you click a button and that runs a formula that comes up with a number. From that number, I want to be able to allow that to be the percentage chance that a hit is made. Kind of a D&D, 100 sided dice rolling kind of element, but it be completely under the hood. Any idea how to do that? I've been staring at this for days and I just can't figure it out.

Also, bonus question: Where can I use this on an IF statement. Such as, if "If there is a hit, then run formula attribute-attribute=number" and then random dice roll that?

I really appreciate the help, guys.

Comments

  • thespis721thespis721 Member Posts: 4
    Anyone have any ideas?
  • quantumsheepquantumsheep Member Posts: 8,188
    I may be completely wrong, as I'm no maths whizz.

    I implemented a system where when the player finishes a level (so, *if* gamelevelfinished = true) I give the player a percentage of his score added to the score:

    Change attribute percentagescore to (random (.1,1)*gamescore)
    Change attribute gamescore to gamescore+percentagescore

    To display the percentage I put in a display behaviour that says:
    Display (percentagescore/gamescore)*100

    Hope that points you in the right direction - like I say, I'm no maths whiz!

    Cheers,

    QS :D

    EDIT - for the bonus question, you could (in my example) use:

    If player hits enemy
    AND (percentagescore/gamerscore)*100 > 50

    Then HIT enemy

    Otherwise
    MISS enemy

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    QS, does random give you decimal values? I thought it only spits out integers. That would be really nice if it gave real numbers.
  • quantumsheepquantumsheep Member Posts: 8,188
    I'm really not sure - I guess you could if need be get a random number between 1 and 100 and divide by 100 instead?

    QS

    EDIT - just tried that, and it works better :D So I guess you were right, sci :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

Sign In or Register to comment.