Digital Dice

An intriguing but probably simple question to ask, I have a program that lets me roll one digital die. I can set the number of sides, and roll it as much as I want.

repeat
	set maxNum to text returned of (display dialog "Enter in the highest possible number for the computer to \"roll.\"" default answer "6" default button 2)
	try
		set maxNumInteger to maxNum as integer
		set RdmNum to random number from 1 to maxNumInteger
	on error
		display dialog "Only integers" buttons {"Cancel"} default button 1
	end try
	display dialog "You rolled a " & RdmNum & "." buttons {"Quit", "Re-roll"} cancel button "Quit" default button 2
end repeat

Though it’s fun and simple, I was wondering: can I set the amount of dice that I roll? Basically, can I roll two dice and see each of their results? Then, can I set the amounts of sides each die has? I would prefer the first (rolling x dice and seeing the individual results per die) over the second. Thanks! :slight_smile:

Hi. I’d place the value into a handler with parameters, along these lines:


set AppleScript's text item delimiters to return & return
 rolldice(3, 6)
set AppleScript's text item delimiters to ""


on rolldice(diceCount, sidedness)
	set eventList to {}
	repeat diceCount times
		set eventList's end to random number from 1 to sidedness
	end repeat
	display dialog "You rolled " & diceCount & " dice, returning the values: " & return & return & eventList as text
end rolldice

Sorry, I’m not that good at compiling AppleScript :stuck_out_tongue: could you put it into one file? Thanks