因此,我和一个伙伴(主要是伙伴)为我在UT99中进行的比赛创建了一个脚本,因此我们可以随机分配投票过的地图,但是遇到了问题。当我在列表中放置31张以上的地图时,它会随机显示%D值而不是地图名称,但是列表中的31张以下地图永远不会成为问题。我的清单中有46张地图。这是一行的脚本行。如何解决此问题的任何帮助都将非常有用。我的好友似乎认为我们需要改用动力壳,但是目前我们俩都不在那。感谢您对此事的任何帮助。
echo on
set loop=0
set listnum=0
if EXIST maplist.csv del maplist.csv
set /p gennum=Number of map lists to generate?
rem #=============================================================
rem #===== Get list of maps from maplist.txt
rem #=============================================================
if NOT EXIST maplist.txt echo maplist.txt not found. Please create map
list&&pause
for /f %%a in (maplist.txt) do (
call :build_list %%a
)
rem #=============================================================
rem #===== Generate random numbers and create maplist.csv
rem #=============================================================
:start
set /a mnum1=%random% %% %listnum% + 1
:num2
set /a mnum2=%random% %% %listnum% + 1
if %mnum2%==%mnum1% goto num2
:num3
set /a mnum3=%random% %% %listnum% + 1
if %mnum3%==%mnum1% goto num3
if %mnum3%==%mnum2% goto num3
for /F "tokens=%mnum1%,%mnum2%,%mnum3% delims=," %%B in ("%maplist%") do
echo %%B - %%C - %%D >> maplist.csv
set /a loop=%loop% + 1
if not %loop%==%gennum% goto start
goto end
rem #=============================================================
rem #=========== Functions
rem #=============================================================
:build_list
if "%maplist%"=="" (
set maplist=%1
) else (
set maplist=%maplist%,%1
)
set /a listnum=%listnum% + 1
goto:eof
rem #=============================================================
rem #=========== Echo number of random map lists created and open csv
rem #=============================================================
:end
echo %gennum% lists generated
maplist.csv
答案 0 :(得分:1)
我启用了延迟扩展并实现了伪数组(如Squashman建议的那样)。优点:没有令牌限制。
@echo off
setlocal enabledelayedexpansion
REM next line for generating a "demo maplist":
(for /l %%a in (1,1,50) do echo Map%%a)>maplist.txt
set loop=0
set listnum=0
if EXIST maplist.csv del maplist.csv
set /p gennum=Number of map lists to generate?
rem #=============================================================
rem #===== Get list of maps from maplist.txt
rem #=============================================================
if NOT EXIST maplist.txt echo maplist.txt not found. Please create map list&&pause
set listnum=0
for /f %%a in (maplist.txt) do (
set /a listnum+=1
set map[!listnum!]=%%a
)
rem #=============================================================
rem #===== Generate random numbers and create maplist.csv
rem #=============================================================
:start
set /a mnum1=%random% %% %listnum% + 1
:num2
set /a mnum2=%random% %% %listnum% + 1
if %mnum2%==%mnum1% goto num2
:num3
set /a mnum3=%random% %% %listnum% + 1
if %mnum3%==%mnum1% goto num3
if %mnum3%==%mnum2% goto num3
echo !map[%mnum1%]! - !map[%mnum2%]! - !map[%mnum3%]!>>maplist.csv
set /a loop+=1
if not %loop%==%gennum% goto start
goto end
rem #=============================================================
rem #=========== Echo number of random map lists created and open csv
rem #=============================================================
:end
echo %gennum% lists generated
maplist.csv
(请注意:CSV
代表Comma Separated Values
,所以我不希望有类似alpha - beta - gamma
的东西-但这当然是常见的约定)