保存并加载.bat游戏-单个数字错误 [英] Save and Load .bat game -- Error with single numbers

查看:40
本文介绍了保存并加载.bat游戏-单个数字错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此问题中,保存并加载.bat游戏我使用了Mat的答案.

In this qustion, Save and Load .bat game I used Mat's answer.

但是现在我遇到了使用上述答案保存"数字的问题.

But now I have a problem with "saving" numbers using said answer.

如果变量不是两位数(例如1或0),它将把变量另存为",这样,只要您执行任何需要该变量的操作,游戏就会崩溃.游戏在此之前将变量设置为精细.

If the variable is not double digits (for example 1 or 0) it will "save" the variable as " " and thus will crash the game whenever you do anything that needs that variable. The game sets the variable fine before that.

例如,如果我拿起碎布,然后键入Inv,它将说我拿着碎布.如果我随后保存并再次加载,然后键入Inv,它不会说我持有任何东西!

For example if I pick up the rag, then type Inv, it will say I'm holding the rag. If I then save and load again, then type Inv, it wont say I'm holding anything!

如果%raghave%= 00

(我也在Notepad ++中打开了保存文件,因此可以看到 set RagHave = )

(I also have the save file open in Notepad++ and so can see that set RagHave=)

(另外,如果我将Mat的代码与空格一起使用,则该变量将设置为"set RagHave = 1 ",因此在末尾添加一个空格)

(Also if I use Mat's code with the spaces, then the variable is set as "set RagHave=1" and so adds a space at the end)

推荐答案

问题是Mat的解决方案!为了更好的理解,我重复他的解决方案

The problem is Mat's solution! For better understanding I repeat his solution

@echo @ECHO OFF           > savegame.cmd
@echo SET ITEMS=%ITEMS%   >> savegame.cmd
@echo SET HEALTH=%HEALTH% >> savegame.cmd
@echo SET MONEY=%MONEY%   >> savegame.cmd

我认为它有很多缺点.
@ 前缀不是必需的.
重定向对于每行重复一次(我不喜欢冗余).
它需要空格,因为没有空格会出现数字问题.

In my opinion, it has multiple disadvantages.
The @ prefix isn't necessaray.
The redirection is repeated for each line (I don't like redundancy).
It needs the spaces, as without spaces you got problems with numbers.

带有项目= 1的样本

@echo set ITEMS=1>>savegame.cmd

这不会导致写入 set items = 1 ,而是将 set items = 写入 1>> savegame.cmd 1 >>标准流.

This results not in writeing set items=1 it writes set items= to 1>>savegame.cmd 1>> is the standard stream.

您可以使用

(
    echo @ECHO OFF
    echo SET "ITEMS=%ITEMS%"
    echo SET "HEALTH=%HEALTH%"
    echo SET "MONEY=%MONEY%"
) > savegame.cmd

引号用于确保该集合后的隐藏"空格被忽略.

The quotes are used to ensure that "hidden" spaces after the set are ignored.

顺便说一句.如果%raghave%= 00 ,(您需要两个等号),则使用这样的结构是个坏主意,因为 00 不是一个普通数字,您不能用它进行计数或计算,最好改用 0 .

Btw. It's a bad idea to use a construct like if %raghave% = 00, (you need two equal signs), as 00 isn't a normal number you can't count or calculate with it, it's better to use 0 instead.

然后这也应该起作用

set /a items=0
set /a items=items+1
set /a items=items-1
if %items%==0 echo There are no items

这篇关于保存并加载.bat游戏-单个数字错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆