Copy link to clipboard
Copied
I have a script to roll six side dice,
var roll = Math.random() * 6+1;
this.getField("Dice").value = roll;
This may sound complicated but I want to set percentage to get 6 to be more then other numbers, is that possible with javascript?
Copy link to clipboard
Copied
First of all use Math.floor() to get integer otherwise you won't get whole number.
Secondly it's not that complicated at all, just add more numbers to die and use if else to set extra numbers to be 6,
for example lets use 8 numbers in a die, use script like this:
var roll = Math.floor(Math.random() * 8)+1;
if(roll == 7 || roll == 8)
this.getField("Dice").value = 6;
else
this.getField("Dice").value = roll;
If die rolls 7 or 8 it will show as six.
Copy link to clipboard
Copied
Use this:
var roll = Math.floor(Math.random() * 30)+1;
if(roll > 20)
this.getField("Dice").value = 20;
else
this.getField("Dice").value = roll;
Copy link to clipboard
Copied
First of all use Math.floor() to get integer otherwise you won't get whole number.
Secondly it's not that complicated at all, just add more numbers to die and use if else to set extra numbers to be 6,
for example lets use 8 numbers in a die, use script like this:
var roll = Math.floor(Math.random() * 8)+1;
if(roll == 7 || roll == 8)
this.getField("Dice").value = 6;
else
this.getField("Dice").value = roll;
If die rolls 7 or 8 it will show as six.
Copy link to clipboard
Copied
Thank you so much. Another question if I have dice with 30 numbers and I want to make 20 and above all roll 20?
Copy link to clipboard
Copied
Use this:
var roll = Math.floor(Math.random() * 30)+1;
if(roll > 20)
this.getField("Dice").value = 20;
else
this.getField("Dice").value = roll;

