Solved How Do I Make A Random %Chance in (Notepad) Batch?

September 30, 2017 at 18:42:13
Specs: Windows 10
I'm using Notepad to make a simple Dungeons and Dragons 1-20 number generator, and while trying to make little quotes to go along with the number I rolled, I found that I have no clue how to make it alternate between quotes. Heres what I've got so far:

@echo off
color 07
ECHO ==================================
ECHO 1 To 20, Are The Odds In My Favor?
echo.
ECHO Roll That Die!
ECHO ==================================
pause>nul
echo.
:start
set /a num=%random% %%20 +1
echo %num%
if %num%==1 ECHO "....This isn't gonna be good..."
if %num%==1 COLOR cf
if %num%==1 pause>nul
if %num%==1 echo.
if %num%==1 color 07
if %num%==1 goto start

if %num%==2 ECHO Its gonna hurt, but it's not the worst.
if %num%==2 COLOR 0c
if %num%==2 pause>nul
if %num%==2 echo.
if %num%==2 color 07
if %num%==2 goto start

if %num%==3 ECHO Ouch. Unlucky, eh?
if %num%==3 COLOR 0c
if %num%==3 pause>nul
if %num%==3 echo.
if %num%==3 color 07
if %num%==3 goto start

if %num%==4 ECHO Oh well, you can't always roll high numbers.
if %num%==4 color 04
if %num%==4 pause>nul
if %num%==4 echo.
if %num%==4 color 07
if %num%==4 goto start

if %num%==5 ECHO Halfway there to being halfway decent.
if %num%==5 color 04
if %num%==5 pause>nul
if %num%==5 echo.
if %num%==5 color 07
if %num%==5 goto start

if %num%==6 ECHO Probably a fail, but I've crossed the halfway point!
if %num%==6 color 0e
if %num%==6 pause>nul
if %num%==6 echo.
if %num%==6 color 07
if %num%==6 goto start

if %num%==7 ECHO Lets hope my enemy is weak.
if %num%==7 color 0e
if %num%==7 pause>nul
if %num%==7 echo.
if %num%==7 color 07
if %num%==7 goto start

if %num%==8 ECHO Comon, I can definitely roll better.

if %num%==9 ECHO One higher woulda been preferred.

if %num%==10 ECHO The Turning Point!
if %num%==10 color 0A
if %num%==10 pause>nul
if %num%==10 echo.
if %num%==10 color 07
if %num%==10 goto start

if %num%==11 ECHO A bit stronger than last time!
if %num%==11 color 0A
if %num%==11 pause>nul
if %num%==11 echo.
if %num%==11 color 07
if %num%==11 goto start

if %num%==12 ECHO Definitely stronger than last time!
if %num%==12 color 0A
if %num%==12 pause>nul
if %num%==12 echo.
if %num%==12 color 07
if %num%==12 goto start

if %num%==13 ECHO You (probably-most definitely) won't get away with this!
if %num%==13 color 0A
if %num%==13 pause>nul
if %num%==13 echo.
if %num%==13 color 07
if %num%==13 goto start

if %num%==14 ECHO You're in my realm now!
if %num%==14 color 0A
if %num%==14 pause>nul
if %num%==14 echo.
if %num%==14 color 07
if %num%==14 goto start

if %num%==15 ECHO Did you hit something? Did you steal something? Oooh! I Wanna Know!
if %num%==15 color 0D
if %num%==15 pause>nul
if %num%==15 echo.
if %num%==15 color 07
if %num%==15 goto start

if %num%==16 ECHO Dad would be proud, probably.
if %num%==16 color 0B
if %num%==16 pause>nul
if %num%==16 echo.
if %num%==16 color 07
if %num%==16 goto start

if %num%==17 ECHO Voimas Hiilgus Tuhande Paikese Eest!
if %num%==17 color 0B
if %num%==17 pause>nul
if %num%==17 echo.
if %num%==17 color 07
if %num%==17 goto start

if %num%==18 ECHO I'm in a good mood!
if %num%==18 color 2B
if %num%==18 pause>nul
if %num%==18 echo.
if %num%==18 color 07
if %num%==18 goto start

if %num%==19 ECHO Dad WILL be proud!
if %num%==19 color 2B
if %num%==19 pause>nul
if %num%==19 echo.
if %num%==19 color 07
if %num%==19 goto start

if %num%==20 ECHO YOU BETTER HOPE I SHOW YOU MERCY, BECAUSE THIS AXE WILL HURT.
if %num%==20 color 24
if %num%==20 pause>nul
if %num%==20 echo.
if %num%==20 color 07
if %num%==20 goto start


echo.
echo.
pause>nul
goto start

(Yes the colors are supposed to be ugly like that + ignore the weird personal quotes its for my character) How would I make it so that when getting a 1, I could alternate between getting a quote like "Oh no.." and "Damn it!"


See More: How Do I Make A Random %Chance in (Notepad) Batch?

Reply ↓  Report •

#1
October 2, 2017 at 08:25:01
✔ Best Answer
You already figured out how to set a ver 1 to 20.
Start with this so you can use !VAR!
@echo off & setLocal enableDELAYedeXpansioN

set/a R=!RANDOM!%%20+1

And save a whole bunch of clutter by avoiding the if == mess and use:

CALL :!R! & goto :eof

:1
echo msg one
goto :eof

...

:20
echo msg twenty
goto :eof

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#2
October 2, 2017 at 09:19:48
That said, if you're really on Win10, you should probably avoid batch, as Microsoft's trying to depreciate it. PowerShell's the replacement, and it's not a bad scripting language (unlike batch):
$quotes = @("") * 20; $color = @(@{}) * 20
$quotes[0]  = @("....This isn't gonna be good...", "Critical miss", "Oh no..", "Damn it!", 
                "Hold my beer")
$quotes[1]  = @("Its gonna hurt, but it's not the worst.")
$quotes[2]  = @("Ouch. Unlucky, eh?")
$quotes[3]  = @("Oh well, you can't always roll high numbers.")
$quotes[4]  = @("Halfway there to being halfway decent.")
$quotes[5]  = @("Probably a fail, but I've crossed the halfway point!")
$quotes[6]  = @("Lets hope my enemy is weak.")
$quotes[7]  = @("Comon, I can definitely roll better.")
$quotes[8]  = @("One higher woulda been preferred. ")
$quotes[9]  = @("The Turning Point!")
$quotes[10] = @("A bit stronger than last time!")
$quotes[11] = @("Definitely stronger than last time!")
$quotes[12] = @("You (probably-most definitely) won't get away with this!")
$quotes[13] = @("You're in my realm now!")
$quotes[14] = @("Did you hit something? Did you steal something? Oooh! I Wanna Know!")
$quotes[15] = @("Dad would be proud, probably.")
$quotes[16] = @("Voimas Hiilgus Tuhande Paikese Eest!")
$quotes[17] = @("I'm in a good mood!")
$quotes[18] = @("Dad WILL be proud!")
$quotes[19] = @("YOU BETTER HOPE I SHOW YOU MERCY, BECAUSE THIS AXE WILL HURT.", "Critical hit")
$color[0]  = @{"b"="Red";       "f"="White"}
$color[1]  = @{"b"="Black";     "f"="Red"}
$color[2]  = @{"b"="Black";     "f"="Red"}
$color[3]  = @{"b"="Black";     "f"="DarkRed"}
$color[4]  = @{"b"="Black";     "f"="DarkRed"}
$color[5]  = @{"b"="Black";     "f"="Yellow"}
$color[6]  = @{"b"="Black";     "f"="Yellow"}
$color[7]  = @{"b"="Black";     "f"="Gray"}
$color[8]  = @{"b"="Black";     "f"="Gray"}
$color[9]  = @{"b"="Black";     "f"="Green"}
$color[10] = @{"b"="Black";     "f"="Green"}
$color[11] = @{"b"="Black";     "f"="Green"}
$color[12] = @{"b"="Black";     "f"="Green"}
$color[13] = @{"b"="Black";     "f"="Green"}
$color[14] = @{"b"="Black";     "f"="Magenta"}
$color[15] = @{"b"="Black";     "f"="Cyan"}
$color[16] = @{"b"="Black";     "f"="Cyan"}
$color[17] = @{"b"="DarkGreen"; "f"="Cyan"}
$color[18] = @{"b"="DarkGreen"; "f"="Cyan"}
$color[19] = @{"b"="DarkGreen"; "f"="DarkRed"}

"==================================
1 To 20, Are The Odds In My Favor?

Roll That Die! ('Q' to quit)
=================================="
while ([Console]::ReadKey($true).Key -ne 'Q') { 
  $roll = Get-Random -Min 1 -Max 21 #-Max needs to be realMaxValue + 1
  Write-Host "$roll`: $(Get-Random -C 1 -In $quotes[$roll-1])" `
   -f $color[$roll-1]["f"] -b $color[$roll-1]["b"]
}

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •
Related Solutions


Ask Question