Need batch help..again
Ok, well i found someone elses C++ code for playing Rock Paper Scissors, and wanted to make my own for batch.
- How do i configure it so that the computer picks a random option?
- What is wrong with the code so far? I can go through it fine until i come across the :rock portion, becuse no matter what i pick, it always goes to rock..any help?
title Rock, Paper, Scissors!
echo Welcome to Rock, Paper, Scissors.
echo If you do not know how to play, read the instructions. I suggest you do to learn what keys are for what option.
pause
set /p info=Would you like to read the instructions? (y or n)
if %info% equ y goto info
if %info% equ n goto game
:game
cls
echo Ok, when you are ready to start the game, press either 0, 1, or 2.
set /p 012=What will you choose?
if %012% equ 0 goto rock
if %012% equ 1 goto scissors
if %012% equ 2 goto paper
:rock
cls
echo You picked rock, press any key to see what the computer will choose.
pause
goto game
:scissors
cls
echo You picked scissors, press any key to see what the other play will choose.
pause
goto game
:paper
cls
echo You picked paper, press any key to see what the computer will choose.
pause
goto game
:info
cls
echo To play this game, you type 0 for rock, 1 for paper, and 2 for scissors.
pause
echo Rock will beat scissors, scissors will be paper, and paper will beat rock.
pause
echo To continue to the game, press any key.
pause
goto game```
Thank you
Well, I know what the problem is, but I don't exactly know why it is a problem, lol. I don't really know the features of the set command too well, but apparently the problem is the %012% part. I changed:
if %012% equ 0 goto rock
if %012% equ 1 goto scissors
if %012% equ 2 goto paper```
to:
```markupset /p num=What will you choose?
if %num% equ 0 goto rock
if %num% equ 1 goto scissors
if %num% equ 2 goto paper```
And selecting each number worked. Although, I don't see how the computer picks a number on the second time round, since all it does is go back to asking you what you want to pick :whoa:
But, I'm pretty sure it was the numbers giving you the trouble :)
Uber0n wrote: I don't even think it's possible making random numbers in batch..?
I think you should learn some C++ and you'll find your problems a lot easier to solve ;)
if you want to do randoms in bat uyou use this function__ %random% __
but it generates a number in the 32000's or something. so i figured if you use a "set /a" function you could divide it into a smaller number like this:
set /a a=%random% set /a a=%random% / 8000 if %a% equ 1 goto p1 if %a% equ 2 goto p1 if %a% equ 3 goto p1 if %a% equ 0 goto p0
by dividing by 8000 it gave 4 random choices(you can of course divide by other numbers)
"this is a clip from a small batch rpg game I am working on if anyone would like me to i'll post it when i'm for other people to test and enjoy":D