So I'm writing a script that can tell if an action has already been performed. I started off with a 2x2 array with 0s in it. I wanted to randomly store three 1s among the four elements and if the element is already storing 1, echo Repeated to notify the user. This is the code I have so far and it doesn't echo Repeated even if the same element is chosen more than once.
@echo off
setlocal EnableDelayedExpansion
::::::::::::::::::::::::::::::::::::::::::::Creating a 2x2 zero array
for /l %%y in (0,1,1) do (
for /l %%x in (0,1,1) do (
set map[%%x][%%y]=0
)
)
::::::::::::::::::::::::::::::::::::::::::::Putting 1s in elements randomly
for /l %%x in (1,1,3) do (
set /a j=!Random!%%2
set /a i=!Random!%%2
if !map[%i%][%j%]! EQU 0 (set map[!i!][!j!]=1) else (echo Repeated)
)
::::::::::::::::::::::::::::::::::::::::::::Result
echo !map[0][0]!!map[1][0]!
echo !map[0][1]!!map[1][1]!
echo.
pause
I read something related online and am pretty sure it has something to do with the "setlocal EnableDelayedExpansion" thing but I don't know how to do it. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire