: :
This message was edited by Circu at 2006-5-8 13:52:12
: : Hello everone, I was wondering if somone could help me out with this problem I am having. I am making a text based rpg in python and I am geting stuck on trying to import a moudle function I made into another part of my programe. I will Show you the code I have so far and the moudle I made for my game and then I will list the error I keep geting hoping somone might be able to help me out.
:
: Thanks for choosing Python to code your game in. It's a great language and I hope you grow to like it as much as I do.
:
: : import Info
: : Player = Info.Player()
:
: Generally speaking, it's convention to give modules lowercase names and classes proper names. Other than that, I see nothing wrong with these two lines.
:
: : Mining = "Mining"
: : Mining = str(Mining)
: : BlackSmithing = "BlackSmithing"
: : BlackSmithing = str(BlackSmithing)
: : Farming = "Farming"
: : Farming = str(Farming)
:
: This is redundant. "Mining" is already a string, and python is smart enough to know that because of the quotes. You don't need to do the str() call.
:
: : That is the main file And I am Importing the Info moudle I made.
:
: It's a little crufty, as far as code goes, but you're clearly a beginner so I will say that it's not bad for an early attempt. Here is one way I may have written your "Main" module:
:
:
: #This is going to be the main part of the programe it will be resonabile for
: #running the programe.
:
: import info
:
: TITLE = """\t\t\t Quest For Power
:
: \t\t\t Made and designed By:
: \t\t\t Christopher Ross
: """
:
: INTRO = """Welcome, %s, well let me tell you a little about this world.
: You will begin your adventure as a Noivce. You will be able to choose
: one of the beginning jobs which are: Mining, BlackSmithing and Farming.
: There are other advanced jobs, but we wont go in to them yet.
: After you choose your beginning job you will want to go to the shop for
: that job. The NPC there will help you along your path.
: """
:
: JOB_CHOSEN = """You have chosen %s as your beginning job, please go visit the
: %s NPC for your initial quest."""
:
: def get_name():
: name = None
: while not name:
: name = raw_input("Please enter you character name >>>").strip()
: return name
:
: def get_age():
: age = 0
: while not age:
: try:
: age = int(raw_input("Please enter how old you are >>>"))
: except ValueError:
: print "Invalid age, please try again!"
: age = 0
:
: def get_job():
: print "Available jobs:\n\t(M)ining\n\t(B)lacksmithing\n\t(F)arming"
: job = ' '
: while job not in 'MmBbFf':
: job = raw_input("Please select a job [M,B,F] >>>")[0]
: if job in 'Mm':
: job = 'Mining'
: elif job in 'Bb':
: job = 'Blacksmithing'
: elif job in 'Ff':
: job = 'Farming'
: return job
:
: def main():
: try:
: print TITLE
: name = get_name()
: age = get_age()
: print INTRO % name
: job = get_job()
: print JOB_CHOSEN % (job, job)
: except:
: print "Goodbye."
:
: if __name__ == '__main__': main()
:
:
: There are probably some ideas in there that are new to you, so let me know if you have any questions about any of it.
:
: : Now this is going to be the Info Moudle script
: :
: : #This is going to be the player moudle, it is going to have the player stats inventory and job list
: :
: :
: : class Player(object):
: : def Stats(self):
: : Strength = 5
: : Strength = int(Strength)
: : Stamina = 5
: : Stamina = int(Stamina)
: : Intellegnce = 5
: : Intellegnce = int(Intellegnce)
: : Rank = "Novice"
: : Rank = str(Novice)
: : print "Your Strength is",Strength,"\n"
: : print "Your Stamina is",Stamina,"\n"
: : print "Your Intellegnce is",Intellegnce,"\n"
: : print "Your Rank is",Rank,"\n"
: :
: : def Inventory(self):
: : Inventory = []
: : print "Your Items are: "
: : for items in Inventory:
: : print Items
: :
: : def Jobs(self):
: : BlackSmithingRank = 0
: : BlackSmithingRank = int(BlackSmithingRank)
: : MiningRank = 0
: : MiningRank = int(MiningRank)
: : FarmingRank = 0
: : FarmingRank = int(FarmingRank)
: : AlchemyRank = 0
: : AlchemyRank = int(AlchemyRank)
: : Jobs = []
: :
: : What I want to do is to be able to use this function in the main file of the game so I figure I would do something like Player = Info.Player()
: : and then call the functions like Player.Stats() but when I do that in the main part of the programe I get a error that says Player.Stats() takes no arguments but I did not prove a Argument I belive some please help me on this I am stuck.
:
: I'm a little confused. I don't think you really know what classes are for. I'm guessing you wanted something like this:
:
:
: #This is going to be the player moudle, it is going to have the player stats
: #inventory and job list
:
:
: class Player(object):
:
: def __init__(self):
: self.strength = 5
: self.stamina = 5
: self.intelligence = 5
: self.rank = 'Novice'
: self.inventory = []
: self.jobs = {
: 'Mining' : 0,
: 'Blacksmithing' : 0,
: 'Farming' : 0,
: 'Alchemy' : 0
: }
:
: def print_stats(self):
: print "Your Strength is", self.strength
: print "Your Stamina is", self.stamina
: print "Your Intellegnce is", self.intelligence
: print "Your Rank is", self.rank
:
: def print_inventory(self):
: if self.inventory:
: print "Your Items are: "
: for item in self.inventory:
: print item
: else:
: print "You have nothing in your inventory."
:
: def print_skills(self):
: print 'Your skills:'
: for job, rank in self.jobs.items():
: print '%s: %d' % (job, rank)
:
:
: Or maybe not. I didn't get the error you described, so I'm not sure what the original problem was, but I hope I helped somehow. Let me know.
:
:
:
infidel
:
:
: $ select * from users where clue > 0
: no rows returned
:
:
:
Wow thank you,I realized what I did wrong. and you post helped cause I did not know that moudles had to be in lower case that was the problem i was having with geting my programe to work thanks alot it helped me out alot.