I want to create a program that lets me type in a number, and then the computer generates a random number between 1 and that number. I have no starting point other than
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
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 randomNumber to random number from 1 to maxNumInteger
on error
display dialog "Only integers" buttons {"Cancel"} default button 1
end try
randomNumber
Thanks, Stefan. After some tweaking (like changing the name from RandomNumber to RdmNum and adding a screen that showed what that was), I got this:
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 & "."
Is there a simple way to change the buttons to say “Re-roll” and “Quit” after you roll and then, if you reroll, it starts you back up at the main screen, and if you click Quit, you exit? It would be nice. Thanks!
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