Я не могу отменить выбор логического значения, но я могу выбрать другие типы данных - PullRequest
0 голосов
/ 25 марта 2020

Я делаю текстовую игру и делю игру на разделы, чтобы сделать возможным сохранение очков. Я использую логические выражения и операторы if, чтобы определить, где находится игрок. Вот немного кода:

from chars import companions_enemies
import time, sys, os, random, pickle

reached_section1 = False

#This is the boolean that determines wether the player has completed the beginning segment

with open("demo_saves.dat", "rb") as f:
reached_section1 = pickle.load(f)

#This is where the error occurs

if reached_section1 != True:
while True:
        time.sleep(1)
        print(p_name)
        time.sleep(1)
        print("Is this the correct name?: ")
        player_sure = input("Yes or No (Y/N)?: ")
        if player_sure == "Y" or "y":
            print("Understood.")
            time.sleep(1)
            print("Saving name and status...")
            main_character = companions_enemies(p_name, 69, 20, 10)
            reached_section1 = True
            with open("demo_saves.dat", "wb") as f:
                pickle.dump(main_character, f, protocol = 2)
            with open("demo_saves.dat", "wb") as f:
                pickle.dump(reached_section1, f, protocol = 2)
            time.sleep(2)
            print("Save complete. Enjoy the demo!")
            time.sleep(2)
            break

else: # Первый раздел игры будет здесь

OUTPUT:

File "/Users/home/PycharmProjects/Almonds Demo/almonds_demo.py", line 7, in <module>
reached_section1 = pickle.load(f)
EOFError: Ran out of input
...