从.txt错误中检索变量;批量

时间:2014-04-11 11:25:02

标签: variables batch-file save call token

:LoadSelect1
set /p Name=Enter character to load:
cls
if EXIST "%Name%_Savefile.txt" goto Load
goto LoadError
:Load
for /f "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26" %%a in (%Name%_Savefile.txt) do call :Process %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z
goto Stats
:Process
set Location=%1
set Name=%2
set Gender=%3
set Age=%4
set Gold=%5
set Hunger=%6
set Illness=%7
set Wounds=%8
set CHP=%9
set MHP=%10
set CMP=%11
set MMP=%12
set DMG=%13
set DFN=%14
set INT=%15
set DEX=%16
set STR=%17
set Head=%18
set Shoulder=%19
set Neck=%20
set Chest=%21
set Glove=%22
set Leg=%23
set Feet=%24
set LTWP=%25
set RTWP=%26

上面的代码用于检索保存到批处理脚本中的.txt文件的变量。变量可以保存到单独的行。使用“呼叫:处理”功能时,%1适用于%1,“%1X”将成为附加编号的%1。同时%2-9为空白,%2X为空白,附有数字。解决方案会很棒。

Pastebin of full code

重新创建:作为批处理文件运行。通过提示直到有9个选项的部分。输入“保存”。关闭并重新打开。转到“加载”选项。输入以前的名称。查看错误。

1 个答案:

答案 0 :(得分:0)

以这种格式保存savefile.txt会更容易:

savefile.txt

Location=AAAA
Name=BBBB
Gender=CCCC
Age=DDDD
Gold=EEEE
Hunger=FFFF
Illness=GGGG
Wounds=HHHH

然后设置保存在savefile.txt中的变量:

for /f "delims=" %%a in (savefile.txt) do set %%a

您也可以将savefile保存为.bat,然后它会如下所示:

set Location=AAAA
set Name=BBBB
----

并且call:savefile.bat将评估您的所有Vars