保存并加载 .bat 游戏 [英] Save and Load .bat game

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

问题描述

我正在做一个用bat写的文字游戏,游戏已经完成了,(或者更多,很好的部分,比如命令,以及可以玩的阶段);但是,我想添加保存游戏的功能,然后重新加载.

I'm making a text game written in bat, and the game has been done, (or more, a good part of it, such as the commands, and at the stage where you can play it); however, I want to add the power to save your game, and load it again.

我认为可以通过让 .bat 文件写入需要保存的变量(例如项目变量)来做到这一点;但是,我不知道该怎么做.任何帮助将不胜感激,谢谢.

I think one could do this by having the .bat file write the variables which need to be saved (such as the item variables); however, I don't know how to do this. Any help would be appreciated, thanks.

我应该说,我可以通过使用:

I should have said, I can make it load, by use of:

 for /f "delims=" %%x in (config.txt) do (set "%%x")

但是,我不知道如何将 .bat 写入文件并保存".

However, I don't know how to make the .bat write to the file and so "save".

推荐答案

试试这个:

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

将在 savegame.cmd 中保存"这三个变量.然后你可以调用那个文件来重新加载变量.

will "save" those three variables in savegame.cmd. Then you can call that file to reload the variables.

(用 for/f 做这件事有点棘手.)

(Doing it with a for /f is quite a bit trickier.)

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

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