[英]How can I have a user save and load their game in my text-based rpg in Visual Studio Code?
I'm making a text-based rpg, but can't think of any way to have a user save their progress and load it back up. 我正在制作基于文本的rpg,但无法考虑让用户保存其进度并将其加载回去。 Any thoughts? 有什么想法吗?
I'm a new programmer, and I haven't done much research, except for on this site. 我是一名新程序员,除了在此站点上之外,我没有做过多的研究。 I thought about writing and reading to and from a text file, but that didn't work. 我考虑过在文本文件中进行读写操作,但这没有用。
Here is the solution I came up with: 这是我想出的解决方案:
def save(what_to_write):
file = open("file_name.txt", "w")
write = file.writelines(what_to_write)
file.close()
file = open("file_name.txt")
cont = file.readline()
print (cont)
file.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.