Reputation: 476
So let me start off with my code:
:Matrix
set /p matrixQ=Are you ready?(Y/N):
if %matrixQ%==Y goto startingMatrix
goto restart
:startingMatrix
set /p loopAmount=How many echos do you want? We recomend 100:
color 2
goto logic
:logic
set counter=0
if %loopAmount% LSS %counter% ( goto tricks )
color 0
pause
goto restart
:tricks
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%
%counter%+=1
goto logic
So what I am trying to do is only print the %random%
numbers a user-inputted amount of times. I tried with a For
loop with no success. So, for some reason, all it does is set the color green and skip right back to the start with the label :restart
. I have absolutely no clue as to why is doesn't go through the if
statement to check if %loopAmount%
is less than %counter%
.
If you can help me out, thank you.
Upvotes: 1
Views: 385
Reputation: 6842
There are a few issues with your script:
The below code works:
:restart
set /p matrixQ=Are you ready?(Y/N):
if %matrixQ%==Y goto startingMatrix
goto restart
:startingMatrix
set /p loopAmount=How many echos do you want? We recomend 100:
color 2
goto logic
:logic
set counter=0
:loop
if %counter% LSS %loopAmount% ( goto tricks )
color 0
pause
goto restart
:tricks
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%
set/a counter=%counter% + 1
goto loop
Upvotes: 0
Reputation: 14325
Counter will always be 0 because of where you set it in the script. You also have the counter and loopAmount variables flipped; you should be checking to see if counter is less than loopAmount. Also, you need to use the set
command to increment counter properly.
:Matrix
set /p matrixQ=Are you ready?(Y/N):
if %matrixQ%==Y goto startingMatrix
goto restart
:startingMatrix
set /p loopAmount=How many echos do you want? We recomend 100:
set counter=0
color 2
goto logic
:logic
if %loopAmount% GTR %counter% ( goto tricks )
color 0
pause
goto restart
:tricks
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%
set /a counter=%counter%+1
goto logic
Upvotes: 1