尝试从文件中查找和加载信息后接收到错误 [英] Receiving error after trying to find and load information from a file in Batch

查看:51
本文介绍了尝试从文件中查找和加载信息后接收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一些实验,目前正在研究小型文本冒险的开始,但是当我测试保存游戏时,程序返回错误系统找不到指定的文件."有人可以帮我吗?(如果有帮助,我正在学校的计算机上.)

I've been doing some experimentation in batch and I'm currently working on the beginnings of a small text adventure, but when I was testing a savegame, the program returned the error "The system cannot find the file specified." Can somebody help me out? (If its any help I'm on a school computer).

这是我所讨论的代码的片段:

Here's the snippet of my code in question:

pushd \\schoolname\MyName$\My Documents\Discount Zork
popd

< savegame.sav (    
  set /p timesPlayed
)

任何帮助将不胜感激.预先感谢!

Any help would be appreciated greatly. Thanks in advance!

推荐答案

我假设您的意图是从您的 savegame.sav 文件中检索多个值,所以也许更改您的从一开始就使用方法论将对您有好处.

I'm assuming that your intention will be to retrieve more than one value from your savegame.sav file, so perhaps changing your methodology from the outset would serve you well.

我提供的第一个建议是,始终在游戏变量中使用相同字符作为前缀.(在下面的示例中,我选择了 {,并且为了改善外观,还为它们添加了} 后缀,这是可选的)

The first advice I'd provide is to always, prefix your in game variables with the same character. (In the example below, I've chosen {, and to improve the look, I've also suffixed them with }, which is optional)

要确保以该字符为前缀且已经存在于本地环境中的变量不会干扰我们的游戏变量,我们首先将其禁用.

To make sure that variables prefixed with that character, and already existing in the local environment, do not interfere with our game variables, we first of all disable them.

现在,我们创建三个带标签的部分,以显示所有变量及其值,将所有变量保存到文件中,并从该文件中加载所有变量.

Now we create three labelled sections for showing all variables with their values, saving all variables to a file, and loading all variables from that file.

然后我们可以根据需要调用这些标签.

We can then call those labels as needed.

下面是一个不同的基本示例,以说明它们的工作原理:

Here's a vary basic example to show them working:

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Rem Changing the current working directory, and pushing the previous to stack
PushD "\\schoolname\MyName$\My Documents\Discount Zork" 2> NUL || GoTo :EOF

Rem Disabling any predefined local variables beginning with {
For /F "Delims==" %%G In ('"(Set {) 2> NUL"') Do Set "%%G="

Rem Simulating first gameplay values for demonstration
Set /A {timesplayed}=3,{health}=80,{strength}=126,{defence}=76,{attack}=57

Rem showing values
Call :ShowVals

Rem saving values to file
Call :SaveVals

Rem zeroing variables for demostration
Set /A {timesplayed}={health}={strength}={defence}={attack}=0

Rem showing new values
Call :ShowVals

Rem loading saved values back into game
Call :LoadVals

Rem proving reloaded values
Call :ShowVals

Rem Returning to previous working directory from stack, and ending script
PopD
GoTo :EOF

:ShowVals
Set {
%SystemRoot%\System32\timeout.exe /T 7 1> NUL
Exit /B

:SaveVals
((Set {) 2> NUL) 1> "savegame.sav"
Exit /B

:LoadVals
For /F "UseBackQ Delims=" %%G In ("savegame.sav") Do Set "%%G"
Exit /B

这篇关于尝试从文件中查找和加载信息后接收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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