Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Random Number between Variable A and Variable B

Status
Not open for further replies.
I'm looking for a script that creates a random number between 2 variables. Variable operations allows for a random number between 2 preset numbers, but not between 2 variables.

This is to find appropriate character statistics for damage and other methods in an evented battle system.

Variable C = Random Number between Variable A and Variable B

For example, [Damage Done] = Random No. (Minimum Damage...Maximum Damage)
While otherwise, [Damage Done] += Random No. (-50...50)
 

OS

Sponsor

Go to Call Script and type: $game_variables[variableC_id] = rand($game_variables[variableA_id]..$game_variables[variableB_id])

EDIT: It may be easier to use Call Script:

a = $game_variables[variableA_id]
b = $game_variables[variableB_id]
$game_variables[variableC_id] = rand(a..b)

If that doesn't work, then sorry.
 
Code:
min = $game_variables[var_a]
max = $game_variables[var_b]
result = [min, rand(max)].max
$game_variables[var_c] = result

That generates a random variable between min and max.
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top