performing action x number of times in batch

September 10, 2010 at 21:21:21
Specs: Windows Vista
I need help. I was making a dice roller for RPG games in batch and I'm trying to figure out a way to take an input, run the number generator a number of times equal to the input, and add all the results. here is the code I'm using to generate dice results:


set /a r=%random%%%<type of dice>+1
echo %r%



See More: performing action x number of times in batch

Report •


#1
September 10, 2010 at 22:16:46
Try this:

:Start

Set Number=1
*Your Commands Here*
SET /a Number +=a
If "%Number%"=="*Number Of Rolls*" GOTO Next
GOTO Start

:Next

Can I put a question here?


Report •

#2
September 10, 2010 at 23:15:31
Thank you, but the code doesn't work. I want the program to "roll the dice" a number of times equal to whatever the user inputs, then take the results and add them together. The code you gave me only loops repeatedly.

Report •

#3
September 11, 2010 at 07:17:43
No it won't...

Where I have "*Your Commands Here*", change that to the results, or whatever needs to be done a number of times.

Where I have"*Number Of Rolls*" change that to how many times you want it to loop. A variable can also work.

EDIT: Try This:

@ECHO OFF

SET Number=1

:Loop

SET /a r=(%Random% %%TYPE OF DICE)+1
ECHO %r%
IF "%Number%"=="NUMBER OF ROLLS" GOTO Next& SET Number=1
SET /a Number +=1
SET /a Total=%Total%+%r%
GOTO Loop

:Next

ECHO Total: %Total%
PAUSE

Can I put a question here?


Report •

Related Solutions

#4
September 13, 2010 at 12:54:41
thx a lot. it works now.

Report •

Ask Question