interaction with my dice roller batch file.

September 13, 2010 at 13:15:00
Specs: Windows Vista
I recently wrote an RPG Dice Roller program in batch. I'm trying to make it so that when you type in something other than a number into the dice roller prompt for module :ADR, it gives you an error. I can't get it to work however because to get the dice roller to work, I have to set whatever the input is as a variable. So no matter what you type in, it will try to run it through the program. Here is what I have so far:
@echo off
:A
cls
echo.
echo.
echo Dice-Roller
echo.
echo Choose what type of dice you wanna roll.
echo.
echo (A) d2
echo.
echo (B) d3
echo.
echo (C) d4
echo.
echo (D) d6
echo.
echo (E) d8
echo.
echo (F) d10
echo.
echo (G) d12
echo.
echo (H) d20
echo.
echo (I) d100
echo.
echo.
set input=
set /p input=Type answer:
if /i "%input%"=="A" (goto ADR)
if /i "%input%"=="B" (goto BDR)
if /i "%input%"=="C" (goto CDR)
if /i "%input%"=="D" (goto DDR)
if /i "%input%"=="E" (goto EDR)
if /i "%input%"=="F" (goto FDR)
if /i "%input%"=="G" (goto GDR)
if /i "%input%"=="H" (goto HDR)
if /i "%input%"=="I" (goto IDR)
goto E

:E
cls
echo.
echo.
echo Please enter the letter next to your choice.
echo.
echo.
pause
goto A

:ADR
cls
echo.
echo.
echo How many do you want to roll?
echo.
echo.
set input=
set /p input=Enter Number Here:
if "%input%"=="%a%" goto p
:p
set number=1
:loop
set /a r=(%random%%%2)+1
echo %r%
set /a a=(%input%)
if "%number%"=="%a%" goto next& set number=1
set /a number +=1
set /a total=(%total%+%r%)
goto loop
:next
set /a total=(%total%+%r%)
echo Total: %total%
pause
exit

the program takes whatever number you want, runs the script to generate a random value between 1 and the number a number of times equal to input, totals the generated numbers, and displays the result. Please help.


See More: interaction with my dice roller batch file.

Report •


#1
September 13, 2010 at 14:04:24
set /p input=Enter Number Here:
ECHO %input%| FINDSTR /r "^[0-9]$"
IF NOT "%ErrorLevel%"=="1" GOTO p
GOTO ADR

*Note: Number's can only range from 0-9.

Can I put a question here?


Report •
Related Solutions


Ask Question