Hi

I am making a text game, and I have made up a basic framework.

I have 2 questions

1) Sometimes, the python interpreter bugs out, like saying that I misspelt a variable 'Item' as 'item' even though I can see the correct spelling infront of me, and the only way to fix it is to restart IDLE, but then it does it again for some other bit of innocent code, Is there any way to fix this permenantly?

2) I run my code, and I get this error:

Traceback (most recent call last):
  File "E:\Tom's Personal Project\src\scenario.py", line 34, in <module>
    s.run()
  File "E:\Tom's Personal Project\src\scenario.py", line 28, in run
    menu.combat_menu(enemy, self.player, action, menu)
  File "E:\Tom's Personal Project\src\gamemain.py", line 21, in combat_menu
    actions.attack(enemy, player, menus)
  File "E:\Tom's Personal Project\src\gamemain.py", line 44, in attack
    menus.combat_menu(enemy, player, self)
TypeError: combat_menu() takes exactly 5 arguments (4 given)

Here is the relevant code:

gamemain.py(part of it):

class Menus():
    def __init__(self):
        pass

    def combat_menu(self, enemy, player, actions, menus):
        print 'You find a fearsome',enemy.name,'!'
        print
        print_monster_stats(enemy)
        print
        print_menu_title('COMBAT MENU')
        print '] Attack'
        print '] Heal'
        print '] Stats'
        print '] Equip'
        print '] Run Away(doesn\'t keep exp)'
        choice = raw_input('>> ')
        inputs = choice.split(' ')
        if inputs[0] == 'attack' or inputs[0] == 'Attack':
            actions.attack(enemy, player, menus)
        if inputs[0] == 'equip' or inputs[0] == 'Equip':
            actions.equip(enemy, player)

scenario.py(part of it):

global menu
menu = Menus()
global action
action = Actions()

class Scenario:
    def __init__(self, number, player):
        self.things  = wl.loadWorlds()[str(number)]
        self.badguys = self.things[0]
        self.items   = self.things[1]
        self.player  = player
        
    def run(self):
        print
        print 'You start searching for a monster...'
        for guy in self.badguys:
            enemy = Monster(guy)
            menu.combat_menu(enemy, self.player, action, menu)

I have been trying to fix 2) for days.
Any help would be greatly appreciated :)
Thanks in advance :)

Why wont you leave Idle alone? There are some good IDE down there:
1. I use Wingware's Personal, but before that I used 101 edition
IMHO, 101 is far best than IDLE and have good debugger

2. Netbeans Early Access - Python

3. DrPython

File "E:\Tom's Personal Project\src\gamemain.py", line 44, in attack
******************************************************
menus.combat_menu(enemy, player, self)
******************************************************
TypeError: combat_menu() takes exactly 5 arguments (4 given

combat_menu is defined as
def combat_menu(self, enemy, player, actions, menus):
The error message says that you only sent it 3 args (+ the class's self) and only two of the args are correct.

saying that I misspelt a variable 'Item' as 'item' even though I can see the correct spelling infront of me

Python does not lie to you. You have mis-spelt the variable name. Take another look at the program name and line number in the error message. You are either looking in the wrong program or at the wrong line. Or it is on the line 2 or more times and you are only looking at one of them. Some advice gained from experience. Always say "how did I screw up this time" and never "this program/computer isn't doing this right". It's never the computer, its always us.

woooee: I right clicked on the error in the python shell, and clicked "Go to file/line" and it took me to the line where I had "Item", but it was telling me that I had spelt it as "item", then when I restarted IDLE, it didn't give me the error anymore.

Post the error message and the line it came from and we'll see if we can get to the bottom of this. You might want to put a try/except around that part of the code and see if you get any more info.

try:
   ## code goes here
except:
   import traceback
   traceback.print_exc()
   raise

I really have no idea why it is doing this, here is the gamemain.py file that is causing the error:

from useful import *

class Menus():
    def __init__(self):
        pass

    def combat_menu(self, enemy, player, actions, menus):
        print 'You find a fearsome',enemy.name,'!'
        print
        print_monster_stats(enemy)
        print
        print_menu_title('COMBAT MENU')
        print '] Attack'
        print '] Heal'
        print '] Stats'
        print '] Monster Stats'
        print '] Equip'
        print '] Run Away(doesn\'t keep exp)'
        choice = raw_input('>> ')
        inputs = choice.split(' ')
        if inputs[0] == 'attack' or inputs[0] == 'Attack':
            actions.attack(enemy, player, menus)
        if inputs[0] == 'equip' or inputs[0] == 'Equip':
            actions.equip(player, inputs[1])
        if inputs[0] == 'Monster Stats' or
        inputs[0] == 'monstet Stats' or
        inputs[0] == 'Monster stats' or
        inputs[0] == 'monster stats':
            print_monster_stats(enemy)        

class Actions():
    def __init__(self):
        pass

    def attack(self, enemy, player, menus):
        dmg = player.damage(enemy)
        if not dmg == 0:
            enemy.hp -= dmg
            print 'You did',dmg,'damage to the',enemy.name,'!'
            menus.combat_menu(enemy, player, self, menus)
            if enemy.deadCheck():
                print 'You killed the',enemy.name,'!'
                exp = player.expgain()
                player.exp += exp
                if player.levelUpCheck():
                    print 'You gained a level!'
                    print 'You are now on level',player.level
        else:
            print 'The',enemy.name,'blocked your attack!'
            menus.combat_menu(enemy, player, self)

    def equip(self, player, name):
        num_not_owned = 0
        for item in player.inventory:
            if not player.inventory[item].name == inputs[1]:    
                num_not_owned += 1
                if num_not_owned == len(player.inventory):
                    print 'You don\'t own that item.'
            else:
                print 'Equiped the',inputs[1]

It gives me a Syntax error the way you posted it on line 25, I messed with it for a little bit, what I come up with is you can not use 'or' they way that you are, I tried slapping a colon there that didnt make it happy. But I am not the best at this.. Nor claim to be, I could be very wrong. I had a difficult time with 'Classes' like this myself.

But here is what I did, I took out the other 'input[0] stuff, and just left the first one, worked fine and clean for me.

if inputs[0] == 'Monster Stats':
    print_monster_stats(enemy)

This above ^ worked fine.
so I think line 26-28 you have structured wrong, or that just wont work, I am not good enough to tell you that for sure.

inputs[0] could only be one word, since you split the raw_input, so the code would be

if inputs[0].lower() == 'monster:
##  or
test = inputs[0].lower()
if test == 'attack':
            actions.attack(enemy, player, menus)
elif test == 'equip':
            actions.equip(player, inputs[1])  ## inputs[1] will not exist
elif test == 'monster':
            print_monster_stats(enemy)

Makes sense when I see it, I could not think of the reason why, but I knew it was they way input was structured..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.