Except bugging without being called

Asked

Viewed 41 times

-1

well, I made a "minigame" with even a save/load system. the problem is that after saving or loading the game, ask to "mine", the script returns me the except command of the first command.

guy:

i save, load, save. when I "mine" it shows except save first, if I mine dnv, it shows the except of "load", dnv dai it shows the except of the "save".

i.e., shows except of commands in sequence, even if the function is not called.

this happened dps I try to implement a value to mine, like mine 3 at a time or 5. the "Minepower"

print('"jogo" ainda em desenvolvimento, relatar qualquer bug ao desenvolvedor\n')
tier1=0
tier2=0
MinePower=1
def setup(tier1, tier2,MinePower):
    tier1=int(tier1)
    tier2=int(tier2)

    print("--------------------------------------")
    print("| Melhorar     Minerar    Salvar     |")
    print("| Carregar     Inventario            |")
    print("--------------------------------------")

    acao=input()

    if acao=='melhorar' or acao=='Melhorar':
        if tier1>=9:
            tier1=tier1-9
            tier2+=1
            print('\nVocê comprimiu suas pedras, agora você tem',tier2,'Pedras Tier 2 e',tier1,'Pedras Tier 1.' )
            setup(tier1, tier2, MinePower)

        else:
            print("\nVocê não tem pedras suficientes.")
            setup(tier1, tier2, MinePower)

    elif acao=='minerar' or acao=='Minerar':
        tier1=tier1+MinePower
        print("\nVocê minerou",MinePower,"Pedra, agora você tem",tier1,"Pedras.")
        setup(tier1,tier2,MinePower)

    elif acao=='salvar' or acao=='Salvar':
        save(tier1,tier2,MinePower)

    elif acao=='carregar' or acao=='Carregar':
        carregar(tier1,tier2,MinePower)

    elif acao=='Inventario' or acao=='inventario':
        print("Pedras:",tier1)
        print("Pedras Comprimidas:",tier2)
        setup(tier1, tier2, MinePower)

    else:
        print("-=-=-=-=-=-=-=Comando desconhecido=-=-=-=-=-=-=-")
        setup(tier1,tier2,MinePower)

    setup(tier1,tier2,MinePower)

def save(SaveTier1,SaveTier2,SaveMinePower):

    try:
        SaveFile=open("Save.txt","w")
        SaveFile.write(str(SaveTier1)+'\n'+str(SaveTier2)+'\n'+str(SaveMinePower))
        print('Um Save nomeado "Save" foi criado')
        SaveFile.close()
        setup(SaveTier1,SaveTier2,SaveMinePower)

    except:
        print("Erro ao salvar arquivo")
        setup(SaveTier1,SaveTier2,SaveMinePower)

    setup(SaveTier1,SaveTier2,SaveMinePower)

def carregar(BackupT1,BackupT2,BCMinePower):
    try:
        CarrFile=open("Save.txt","r")
        CarrTier1=CarrFile.readline()
        CarrTier2=CarrFile.readline()
        CarrMinePower=CarrFile.readline()

        CarrFile.close()
        setup(CarrTier1,CarrTier2,CarrMinePower)

    except:
        print("Erro ao carregar arquivo, seu caminho ou nome podem ter sido modificados.")
        setup(BackupT1, BackupT2, BCMinePower)

    setup(BackupT1,BackupT2,BCMinePower)






setup(tier1,tier2,MinePower)
  • The setup() function is being called twice.

  • but the except being called n is in setup

  • In each function you call the setup three times. That’s right? You call inside the try, within the except and then off the block try/catch, which implies that the function setup will be executed at least twice each call of one of the functions. This doesn’t seem to make sense.

1 answer

-1

It didn’t make much sense, but I did it. at the beginning of the script, within the setup, I define Tier1=int(Tier1) and the same with tier2. I just did the same thing with Minepower.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.