need help with a batch file

SET /A x=%RANDOM%%%2%

Outputs 1 or 0

It's a command in the code yes? so I was wondering were to put it.
 
SET /A x=%RANDOM%%%2%

Outputs 1 or 0

It's a command in the code yes? so I was wondering were to put it.


Okay, took me a little bit because I had to rewrite almost the whole code.
But here is a working "game".
Code:
@ECHO OFF
@Color 09
:reset
@SET /A yournumber=150
GOTO :start

:start
CLS
ECHO Numbergrow -made by MaRtIn C. in 2oo9
ECHO Edited by Vampist
ECHO Try to grow your number to 5000 to win
ECHO and make sure it stays above 50 or you lose.
ECHO You start at 100 and You can type in 25 50 75 100 125 150
ECHO 175 or 200. The number you type in will either be added
ECHO or subtracted from your number.
ECHO.
ECHO Type in play to start the game or color to adjust the color
ECHO Then press ENTER
ECHO.
SET /P command1=
IF %command1% == play GOTO :play
IF %command1% == color GOTO :colorset
GOTO :start

:colorset
CLS
ECHO Type in 2 letters/numbers and then press ENTER
ECHO Color Key
ECHO 0= Black 2= Green 4= Red 6= Yellow 8= Gray
ECHO 1= Blue 3= Aqua 5= Purple 7= White 9= Light Blue
ECHO.
ECHO A= Light Green C= Light Red E= Light Yellow
ECHO B= Light Aqua D= Light Purple F= Bright Blue
ECHO The first letter/number of what you type in is the background
ECHO color, and the second letter/number is the foreground color/text color.
ECHO Example: 01 makes the background color BLACK and the foreground color BLUE.
ECHO.
ECHO Type in 2 letters/numbers and then press ENTER
ECHO.
SET /P colorcode=
Color %colorcode%
CLS
ECHO The color has been set.
ECHO.
pause
GOTO :start


:play
CLS
ECHO Your number is %yournumber%
ECHO You can type in 25 50 75 100 125 150 175 0r 200
ECHO Try to get to 5000 to win and stay above 50 or you lose.
ECHO If you want to start over type reset
ECHO.
ECHO Type in a number or letter and then press ENTER
ECHO.
SET /P toolnumber=
IF %toolnumber% == reset GOTO :reset
IF %toolnumber% == 25 GOTO :rand
IF %toolnumber% == 50 GOTO :rand
IF %toolnumber% == 75 GOTO :rand
IF %toolnumber% == 100 GOTO :rand
IF %toolnumber% == 125 GOTO :rand
IF %toolnumber% == 150 GOTO :rand
IF %toolnumber% == 175 GOTO :rand
IF %toolnumber% == 200 GOTO :rand
GOTO :play

:rand
SET /A myrand = %random%%%2%
if %myrand% == 1 GOTO :add
if %myrand% == 0 GOTO :sub
pause

:add
ECHO ADDED!
SET /A yournumber += %toolnumber%
GOTO :checknum

:sub
ECHO Subtracted!
SET /A yournumber -= %toolnumber%
GOTO :checknum

:checknum
CLS
IF %yournumber%== 5000 GOTO :win
IF %yournumber%== 5025 GOTO :win
IF %yournumber%== 5050 GOTO :win
IF %yournumber%== 5075 GOTO :win
IF %yournumber%== 5100 GOTO :win
IF %yournumber%== 5125 GOTO :win
IF %yournumber%== 5150 GOTO :win
IF %yournumber%== 5175 GOTO :win
IF %yournumber%== 5200 GOTO :win
IF %yournumber%== 5225 GOTO :win
IF %yournumber%== 5250 GOTO :win
IF %yournumber%== 5275 GOTO :win
IF %yournumber%== 5300 GOTO :win
IF %yournumber%== 50 GOTO :lose
IF %yournumber%== 25 GOTO :lose
IF %yournumber%== 0 GOTO :lose
IF %yournumber%== -25 GOTO :lose
IF %yournumber%== -50 GOTO :lose
IF %yournumber%== -75 GOTO :lose
IF %yournumber%== -100 GOTO :lose
IF %yournumber%== -125 GOTO :lose
IF %yournumber%== -150 GOTO :lose
IF %yournumber%== -200 GOTO :lose
IF %yournumber%== -225 GOTO :lose
IF %yournumber%== -250 GOTO :lose
IF %yournumber%== -275 GOTO :lose
IF %yournumber%== -300 GOTO :lose
GOTO :play

:win
CLS
ECHO YOU WIN!!!
GOTO :replay

:lose
CLS
ECHO YOU LOSE
GOTO :replay

:replay
ECHO Play again? yes/no then press ENTER
ECHO.
SET /P replay=
if %replay% == yes GOTO :reset
GOTO :EOF
 
with batch file colour changing

0 = black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = purple
6 = Yellow
7 = white
8 = grey
9 = light blue
A = light green
B = light Aqua
C = Light Red
D = Light purple
E = light yellow
F = Bright white



if you write color 2, the text changes to green, (with a black background)

if you write color 24, the the text changes to red on a green background.

(first number is background colour, last number is text colour), if you only put one number it changes the text colour and defaults the background to 0, black.
 
Python and Perl....
What about them?

If you're saying they're much better, more flexible and modern alternatives to windows batch files these days then I completely agree. Perl especially (I'm not a huge fan of Python!)
 
Other programming language. Python is a language that aims to accomodate lots of different styles of programming into one package (but in my opinion, ends up being a bit half hearted in all of them as a result.) Perl is a straight scripting language that's commonly used for knocking up small applications in the shortest amount of time. You can think of it as a bit like batch scripts - but far more extensive, modern, usable and worthwhile learning!

...If you go down the Perl route though, a word of caution - a lot of Perl programmers just treat Perl as one big hack. The philosophy behind it is usually "let's see how quickly we can write an application to do x", not "let's see how WELL we can write an application to do x". While that's fine if you know good concepts and can apply them already, I wouldn't recommend starting out that way - it'll do BAD BAD things to your coding in the future!
 
Back
Top Bottom