本文介绍了如何批量创建嵌套变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建的批处理游戏中获取嵌套变量. 我希望它可以选择一个随机变量并将其更改为X,但是如果已经选择它,则应返回并选择另一个数字.
I am trying to get nested variables in my batch game i am creating. I want it so that it will choose a random variable and change it to X, but if it is already chosen, it should go back and choose a different number.
set 1=a set 2=b set 3=c set 4=d set 5=e这些是变量,这是代码
setlocal enabledelayedexpansion :eliminator set /a eliminate=(%random * 5) / 32767 + 1 if %%eliminate%%==X goto eliminator echo The letter !!eliminate!! was chosen timeout 5 set %%eliminate%%=X goto eliminator现在,事情是,当我尝试回显它时,它会写出变量的名称而不是值.同样,已经选择的变量将再次被选择.有什么办法可以解决这个问题吗?谢谢.
Now, the thing is, when I try to echo it, it writes the name of the variable instead of the value. Also, variables that have already been chosen are being chosen again. Any way I could fix this? Thanks.
推荐答案尝试一下:
@echo off&setlocal set "var1=a" set "var2=b" set "var3=c" set "var4=d" set "var5=e" :loop set /a rd=%random%%%5+1 if defined var%rd% call echo %%var%rd%%% set "var%rd%=" set "var" >nul 2>&1 && goto:loop..输出(可能有所不同):
..output (may vary):
d a c b e更多推荐
如何批量创建嵌套变量?
发布评论