15% chance TRUE 85% FALSE

how can i easily write this code using an actor's attrubite?

Comments

  • UltraLionBluUltraLionBlu Member Posts: 157

    change attribute game.criticalChance random (1,100)
    rule any
    if game.critical chance = 1
    if game.critical chance = 15
    do....

    rule any
    if game.critical chance = 16
    if game.critical chance = 100
    do..

    In my opinion it could be something like that, but putting 100 if is long, maybe there is a way to include the first 15 numbers in one if and the remaining 85 in another if in the second rule

  • ArmellineArmelline Member, PRO Posts: 5,327

    There are other ways but @UltraLionBlu's way is simple and easy. Except you can say game.criticalChance random(1,100) like he says, but only need one condition. <=15 will give you either 1-15 (yes) or 16-100 (no). If you want to control is via an attribute, you just say <= self.attribute and have self.attribute be the % chance you want.

  • UltraLionBluUltraLionBlu Member Posts: 157

    @Armelline said:
    There are other ways but @UltraLionBlu's way is simple and easy. Except you can say game.criticalChance random(1,100) like he says, but only need one condition. <=15 will give you either 1-15 (yes) or 16-100 (no). If you want to control is via an attribute, you just say <= self.attribute and have self.attribute be the % chance you want.

    Great Armelline, it was so obvious but I didn't think about it :D

  • 3absh3absh Member Posts: 601

    Walaa!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Looks good. If you wanted to do this in a single behavior, you could use:

    Change Attribute self.critical to floor(random(1,100)/85)

    or

    Change Attribute self.critical to floor(random(1,100)/(100-self.criticalChance))

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.