How do I make RNG Buttons with increasing worse odds the more the player clicks on it with mouse?

0 favourites
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hello again.

    I know how to create RNG on a button, however I do not know how to make increasingly worse odds the more that you click on a button. Ideally I would like to program a button that has a hard cap of being only able to be clicked 3 times and that button becomes locked. Each time the player clicks on the button, the button picks a number from a sequence and depending on the number, the player gets a good or bad result. The odds get increasingly worse the more the player clicks on the button.

    How do I do this?

  • For example:

    Variable odds=50
    
    On button clicked 
    
    .. If random(100)<Odds : // success
    .. Else : // fail
    
    .. Subtract 10 from odds
    

    Every click will reduce the odds by 10%. Starts at 50%, and after 5 clicks will be zero.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • is that a global or instance variable?

  • Can be global, or it can be an instance variable on the button for example.

  • ah thank you

  • I gave it a go and I couldn't really understand it

  • random(100) returns a random number from 0 to 100.

    random(100)<50 condition would mean 50% chance.

    random(100)<20 condition is 20% chance.

    random(100)<1 condition is 1% chance.

    By changing the number you can change the odds.

  • When writing random(100)<50 the odds come out as either 0 or 1 and not between 0 or 100. Not having the <50 seems to be working out although the numbers come out as decimals. So I don't know if they're subtracting from the variable or not.

  • This is an evaluation

    Basically it means "Is the value generated by random(100) less than 50?" and it's either true (1) or false (0).

  • Again, the results always come out as 0 or 1 when the variable is set to Random(100)<50. So it doesn't make a difference. Also how can you set something as true or false when the variable isn't a Boolean?

  • Again, the results always come out as 0 or 1 when the variable is set to Random(100)<50

    That is exactly how it's supposed to work.

    Also how can you set something as true or false when the variable isn't a Boolean?

    A boolean is in essence just a 1 (true) or 0 (false).

    Your code is wrong because you already do the comparison in random(100)<50

    And then compare the result of the comparison again with <50. Either you do

    Set Odds to random(100)

    Odds <50 / Odds >50

    OR

    Set Odds to random(100)<50

    Odds = 0 / else

  • Okay I got that working, but how do I then get it so that odds get smaller on each click until it basically hits 0 and then does nothing when you press the button? Also is there a way to change the rolls into whole numbers instead of decimals?

  • Put the odds in a variable that you decrease every click.

  • Is this correct?

  • Not quite. Try it like this. Odds start out at 100% so the first click will always result in success. After 10 clicks the odds are at 0% so a click will always result in failure.

    Think of it like a dice roll. You need a 6 which means the odds are at ~16.67%. You roll the dice, if it lands on 6 it's success (1) if it lands on anything else it's fail (0)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)