Я получаю TypeError: объект int не вызывается

1

Итак, я играю в ролевую игру, и я делаю карту. Ошибка в def называется map1 в верхней части скрипта. ПОЖАЛУЙСТА, ПОЗВОЛЯЙТЕ МЕХ! Кроме того, какое бы решение вы ни выбрали, можете ли вы объяснить, что он делает, я новичок.

weap = 0
fate = 0
gold = 100

#---------------------------------------------------------------------------------
def map1(dellon, forrest, fate):
    print(dellon)
    print("MAP")
    print("---------------------------------------------------------------------------------")
    print("type one of the following numbers, then press enter.")
    if dellon == 1:
        print("\n(1) Dellon")
    if forrest == 1:
        print("(2) Darkwood Forrest")
    if fate == 1:
        print("(3) Fate")
    choice = float(input())
    if choice == 1:
        dellon(0)
    elif choice == 2:
        forrest()
    elif choice == 3:
        fate()
#---------------------------------------------------------------------------------
def forrest():
    print("What do you chose to do:")
    print("(1) Go North\n(2) Go South\n(3) Go East\n(4) Go West\n(5) Go hunting")
    choice = input()
    if choice == 1:
        print("You find Donna picking berries, do you wish to talk to her?")
        print("(1) Yes\n(2) No")
        talk = input()
        if talk == 1:
            pass
        elif talk == 2:
            forrest()
    elif choice == 2:
        Fate()
        fate = 1
    elif choice == 5:
        from random import randint
        hunt = randint(1,3)
        if hunt == 1:
            animal = randint(1,5)
            if animal == 1:
                print("You where ambushed by a wild bear.")
                input()
            elif animal == 2:
                print("You have been ambushed by a wild wolf.")
                input()
            elif animal == 3:
                print("You have been ambushed by a wild bobcat.")
                input()
            elif animal == 4:
                print("You have been ambushed by a wild cyote.")
            elif animal == 5:
                pass
                input()
#---------------------------------------------------------------------------------
def kingsquestdone(gold, dellon, forrest, fate):
    print("KING: I see you have the potions, good work!")
    print("Give them to me, and I will have")
    print("before you leave, here is your pay.  I'll give")
    print("my servant deliver them to the hospital.  And I will give")
    print("you 300 gold for your troubles.")
    gold = gold + 300
    print("Your current gold is "+ str(gold) +".")
    choice = float(input("(1) Go into Dellon\n(2) Map: "))
    if choice == 2:
        map1(dellon, forrest, fate)
    elif choice == 1:
        indellon(1)
#---------------------------------------------------------------------------------
def lockfail():
    print("You have failed to pick the lock.")
    game0()

#---------------------------------------------------------------------------------
def king(name):
    print("KING: Hello "+ name +", I requested your presence because")
    print("we, the people of Dellon, need your help.")
    print("We need you to seek out a berry called")
    print("a jutish berry.  It is for the public hospital, they need")
    print("it to make healing remidies for the sick, and injured.")
    print("--------------------------------------------------------------")
    print("What do you want to say:")
    print("1: Ok, I'll help.\n2: Maybe later.")
    choice = float(input())
    if choice == 1:
        print("KING: Good, the berry is found Darkwood Forrest.  A woman named Donna.")
        print("She has much exxperience in picking these berries, talk to")
        print("her to learn how, and where to pick them.  After you pick")
        print("three bushes, return to me, and I will give you your pay.")
        input("Press enter to continue into Darkwood Forrest.")
        dforrestent()
#---------------------------------------------------------------------------------
def allberriespicked():
    print("-----------------------------------------------------------------")
    print("\nDONNA: Good, you have collected all of the needed berries.")
    print("I'll take those, and make them into the potions that you need.")
    print("You can return here any time you want to pick some berries")
    print("for me to earn some extra coin.  Return to the King, and deliver")
    print("those berries to him.")
    input("\nPress enter to travel to the king.")
    kingsquestdone(gold)

#---------------------------------------------------------------------------------
def dforrestent():
    def jutish4():
        from random import randint
        berry = randint(1, 2)
        if berry == 1:
            print("---------------------------------------------------------------------")
            print("\nYou have picked one jutish berry bush.")
            input("Press enter to return to Donna.")
            allberriespicked()
        elif berry == 2:
            print("---------------------------------------------------------------------")
            print("\nYou didn'd find the correct bush this time, try again.")
            input("Press enter to continue looking.")
            jutish4()
    def jutish3():
        from random import randint
        berry = randint(1,2)
        if berry == 1:
            print("---------------------------------------------------------------------")
            print("\nYou have picked one jutish berry bush.")
            input("Press enter to continue picking the berries.")
            jutish4()
        elif berry == 2:
            print("\nYou didn'd find the correct bush this time, try again.")
            input("Press enter to continue looking.")
            jutish3()
    def jutish2():
        from random import randint
        berry = randint(1, 2)
        if berry == 1:
            print("---------------------------------------------------------------------")
            print("\nYou have picked one jutish berry bush.")
            input("Press enter to continue picking the berries.")
            jutish3()
        elif berry == 2:
            print("\nYou didn'd find the correct bush this time, try again.")
            input("Press enter to continue looking.")
            jutish2()

    def jutish1():
        print("You enter a field type area with many different types of bushes.")
        input("\nPress enter to look for more jutish berry bushes.")
        from random import randint
        berry = randint(1, 2)
        if berry == 1:
            print("\nYou have picked one jutish berry bush.")
            input("Press enter to continue picking the berries.")
            jutish2()
        elif berry == 2:
            print("\nYou didn'd find the correct bush this time, try again.")
            input("Press enter to look again.")
            jutish1()
    forrest = 1
    print("you have entered the forrest.  You must search")
    print("for Donna as the King has mentioned.")
    print("")
    print("1: Go West\n2: Go North\n3: Go East\n4: Go South")
    choice = float(input("Enter a number to travel in that direction: "))
    if choice == 1:
        print("You end up walking for hours, and never find Donna.")
        print("You end up back at the enterance to Darkwood Forrest.")
    elif choice == 2:
        print("You find Donna, and speak to her.")
        print("\nDONNA: Hello traveler, you must be the one")
        print("delivering the jutish berries for the Dellon hospital.")
        print("To find these berries, you must go to the enterance of the")
        print("forrest, and then travel East, then you will find a")
        print("short, and prickly bush with bright red berries, those are")
        print("the jutish berries you are looking for.  Pick berries from")
        print("four of the bushes, then return to me.")
        input("\nPress enter to continue.")
        jutish1()
#---------------------------------------------------------------------------------
def indellon(first):
    if first == 0:
        print("a man approaches you with a letter.")
        print("MAN:  Hello sir, what is your name?")
        name = input("Name: ")
        print("MAN: Ah, good to meet you, "+ name +", I have a")
        print("message for from the King himself.  He says that")
        print("he wishes to discuss something that will relieve")
        print("your bounty.  I suggest you talk to him imidiatly.")
        print("\nPress enter to conitinue.")
        first = 1
        input()
        king(name)
    elif first == 1:
        print("What do you want to do?")
        print("(1) Leave Dellon")
        print("(2) Go to shops")
        print("(3) Go to residential homes")
        print("(4) Go to the King castle")
        print("(5) Map")
        choice = input()
        if choice == 1:
            dellonsign()
        elif choice == 2:
            dellonshops()
        elif choice == 3:
            dellonhomes()
        elif choice == 4:
            kingscastle()
        elif choice == 5:
            map1(dellon, forrest, fate)

#---------------------------------------------------------------------------------
def fight1(dellon):
    print("you decide to confront the gaurd.")
    en_hp = 10
    pl_hp = 10
    print("press (1) to attack")
    choice = float(input())
    if choice == 1:
        while True:
            if weap == 1:
                from random import randint
                en_damage = randint (1,8)
                pl_damage = randint (5,15)
            elif weap == 0:
                from random import randint
                en_damage = randint (1,8)
                pl_damage = randint (1,10)
            en_hp = en_hp - pl_damage
            pl_hp = pl_hp - en_damage
            print("enemy hp is now:")
            print(en_hp)
            print("your hp is now:")
            print(pl_hp)
            print("press enter to attack again.")
            input()
            if en_hp < 1:
                print("You win this battle, and continue onwards.")
                input("press enter to continue")
                dellon = 1
                dellon(0)
                break
            if pl_hp < 1:
                print("You died.")
                input("press enter to continue")
                fight1()
                break   

#---------------------------------------------------------------------------------
def dellon(dellong):
    if dellong == 1:
        print("as you approach Dellon city gates, you see")
        print("a gaurd, do you want to try to sneak past him")
        print("or confront him?")
        print("(1) sneak past")
        print("(2) confront")
        choice = float(input())
        if choice == 1:
            from random import randint
            n = randint(1,2)
            if n == 1:
                print("you failed to sneak past the gaurd, and must")
                print("commenc battle.")
                fight1(0)
            elif n == 2:
                print("you have succesfully snuck past that gaurd and enter")
                print("the city.")
                dellon = 1
                input()
        elif choice == 2:
            fight1(dellon)
    elif dellong == 0:
        print("(1) enter Dellon")
        print("(2) map")
        choice1 = float(input())
        if choice1 == 1:
            indellon(0)
        elif choice1 == 2:
            map1(dellon, forrest, fate)
#---------------------------------------------------------------------------------
def freedome():
    print("as you step outside, you see two signs, one says")
    print("capitol city of Dellon, and the other says Red Bird Forrest.")
    print("which path do you wish to choose?")
    print("(1) Dellon")
    print("(2) Forrest")
    choice = float(input())
    if choice == 2:
        forrest()
    if choice == 1:
        dellong = 1
        dellon(1)
#---------------------------------------------------------------------------------
def fightwin():
    print("do you wish to search this body?  If you do, you may")
    print("run into more gaurds, if not, you won't get a better weapon.")
    print("(1) yes")
    print("(2) no")
    choice = float(input())
    if choice == 1:
        print("you find a long sword, and continue out the jail")
        print("doors and into freedome once more.")
        weap = 1
        freedome()
    elif choice == 2:
        print("you decide to ignore the body, and continue out the jail")
        print("doors and into freedome once more.")
        weap = 0
        freedome()
#---------------------------------------------------------------------------------
def fight():
    print("You have succesfully busted through the wall, and escaped your cell, but there a gaurd on the other side!  What do you want to do?")
    en_hp = 10
    pl_hp = 10
    print("(1) attack")
    choice = float(input())
    if choice == 1:
        while True:
            from random import randint
            en_damage = randint(1,8)
            pl_damage = randint(1,10)
            en_hp = en_hp - en_damage
            pl_hp = pl_hp - pl_damage
            print("enemy hp is now:")
            print(en_hp)
            print("your hp is now:")
            print(pl_hp)
            print("press enter to attack again.")
            input()
            if en_hp < 1:
                print("You win this battle.")
                input("press enter to continue")
                fightwin()
                break
            if pl_hp < 1:
                print("You died.")
                input("press enter to continue")
                game0()
                break
#--------------------------------------------------------------------------------------
def lockgen():
    from random import randint
    number = randint(1,2)
    if number == 1:
        lfight()
    if number == 2:
        lockfail()
#--------------------------------------------------------------------------------------
def game0():
    print("You wake up very fatigued in a prison cell.")
    print("Your location is unkown, and you must break out.")
    print("Your only choice is to attempt to escape by digging your way")
    print("through the wall with a stone you have found.")
    print("-----------------------------------------------------")
    print("1: Dig through wall")
    prisonchoice = float(input())
    if prisonchoice == 1:
        fight()
    else:
        game0()
def gameover():
    input("Game Over.  Press enter to exit.")

print("")
print("welcome to THE role playing game.")
print("(1) Start game")
print("(2) Type in checkpoint key")
startchoice = float(input())
if startchoice == 2:
    print("Enter in the code.")
    code = float(input())
    if code == 123:
        dellon = 1
        forrest = 1
        fate = 0
        kingsquestdone(gold, dellon, forrest, fate)
elif startchoice == 1:
    game0()
  • 2
    Опубликовать весь трекбек.
Теги:

2 ответа

2
Лучший ответ

В вашей функции у вас есть это утверждение:

if dellon == 1:
    print("\n(1) Dellon")

Это проверяет, равен ли dellon равным 1, и поэтому я предполагаю, что хочу увидеть, является ли dellon целым (как говорит @Blender, это было бы проще с полной трассировкой). Затем вы делаете это

if choice == 1:
    dellon(0)

Если предположить, что dellon на самом деле представляет собой целое число, вы теперь рассматривая его, как будто это функция, назвав его с 0 в качестве аргумента. У вас действительно есть функция dellon которую можно вызвать с помощью аргумента, поэтому вам может потребоваться взглянуть на то, что вы пытаетесь сделать, if dellon == 1: dellon просмотрев остальную часть программы, вы проходите вокруг dellon в форме функции, которую вам не нужно делать, поскольку она ничего не возвращает и уже доступна для других функций.

0

Проблема, с которой вы сталкиваетесь, заключается в том, что вы затеняете функцию dellon (которая объявляется на уровне модуля) с аргументом в вашей функции map1.

Здесь объявление функции:

def dellon(dellong):
    ...

Но вы не можете получить к нему доступ из map1, так как есть аргумент с тем же именем. Поскольку аргумент является локальной переменной в функции, он "теняет" определение внешней функции, поэтому вы не можете добраться до него (по крайней мере, не легко):

def map1(dellon, forrest, fate):
    ...

Исключение запускается немного дальше в map1 где вы map1 вызвать функцию, но вместо этого получаете аргумент (который предположительно является целым):

    if choice == 1:
        dellon(0)

Это должно быть легко исправить. Просто переименуйте либо аргумент в map1 либо функцию dellon.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню