所以我正在做一个小的模拟游戏,我需要系统来识别之前保存在那个账户上的生命值和耐力。
例如,如果玩家退出游戏时有4点生命值,当他们重新加载保存时,他们的生命值仍然是4点。我已经尝试了一点CMD提示符和我的代码,但我似乎找不到方法。有什么帮助吗?
谢谢。
发布于 2014-07-03 11:37:06
哈哈,我试着用>>和<东西。它们生成.txt文件,然后可以由批处理文件监视读取:
@echo off
if %health% EQU 10 (
echo 10 >> health.txt
)
if %health% EQU 9 (
echo 9 >> health.txt
)
if %health% EQU 8 (
echo 8 >> health.txt
)
if %health% EQU 7 (
echo 7 >> health.txt
)
if %health% EQU 6 (
echo 6 >> health.txt
)
if %health% EQU 5 (
echo 5 >> health.txt
)
if %health% EQU 4 (
echo 4 >> health.txt
)
if %health% EQU 3 (
echo 3 >> health.txt
)
if %health% EQU 2 (
echo 2 >> health.txt
)
if %health% EQU 1 (
echo 1 >> health.txt
)这将使批处理文件将健康存储在一个名为health.txt的文本文件中。现在,它需要阅读它。我们将使用set来实现这一点。
@echo off
if %health% EQU 10 (
echo 10 >> health.txt
)
if %health% EQU 9 (
echo 9 >> health.txt
)
if %health% EQU 8 (
echo 8 >> health.txt
)
if %health% EQU 7 (
echo 7 >> health.txt
)
if %health% EQU 6 (
echo 6 >> health.txt
)
if %health% EQU 5 (
echo 5 >> health.txt
)
if %health% EQU 4 (
echo 4 >> health.txt
)
if %health% EQU 3 (
echo 3 >> health.txt
)
if %health% EQU 2 (
echo 2 >> health.txt
)
if %health% EQU 1 (
echo 1 >> health.txt
)
set health=>health.txt基本上,这做的是创建一个文件health.txt,然后读取,并将其命名为变量%health%。(假设% health %是您用来存储此人健康的内容。如果你给我更多的代码,我可以帮你更多。我会更好地理解。简而言之,echo >> health.txt生成health.txt,并设置health=
发布于 2014-07-03 12:32:52
最简单的方法是为要保存的所有变量保留一个前缀。例如,使用$作为要保存的所有变量的前缀。
现在:假设你在某个模糊的变量中有玩家的名字,比如playername。
出于示例目的,设置一些随机值:
set /a $health=7
set /a $stamina=5
set "$somethingelseofinterest=+1 Greatsword of dragon-slaying"
set "playername=Fred"然后,要保存所需的设置,您只需
set $ >"%playername%.game"它会将所有的$变量保存到一个名为"Fred.game“的文件中
为了重新加载感兴趣的变量,
if exist "%playername%.game" (
for /f "delims=" %%a in ('type "%playername%.game" ') do set %%a
) else (
rem in here you could set defaults for a new player
)https://stackoverflow.com/questions/24539282
复制相似问题