Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Need batch help..again


ghost's Avatar
0 0

Ok, well i found someone elses C++ code for playing Rock Paper Scissors, and wanted to make my own for batch.

  1. How do i configure it so that the computer picks a random option?
  2. 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

ghost's Avatar
0 0

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 :)

ghost's Avatar
0 0

Oh ok thank you, and i didnt get too far yet, so i didnt add teh computer choice thing..i just layed it all out.


Uber0n's Avatar
Member
0 0

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 ;)


ghost's Avatar
0 0

aww that sucks…but C++ is waay too complicated atm, so ill stick to learning perl


bl4ckc4t's Avatar
Banned
0 0

Ponguile wrote: aww that sucks…but C++ is waay too complicated atm, so ill stick to learning perl

Perl is your best bet for decent programming without complications. (or Python)

BC


ghost's Avatar
0 0

Should i learn perl or python first? Becuase before i even stumbled upon this website, i tried to learn python..but i only used it for math problems..


bl4ckc4t's Avatar
Banned
0 0

I learned Perl first and Perl is quite easy. It will help you to learn other languages. like C and PHP.

Bl4ckC4t


ghost's Avatar
0 0

Well it may be quite easy, but i have nothing to do with it..and I know a little php, but only the include function, for websites


Uber0n's Avatar
Member
0 0

You have to be a beginner in the beginning ;)

You'll learn fast if you try.


ghost's Avatar
0 0

Ok thanks for the encouragement!


ghost's Avatar
0 0

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