Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I need help, with importing a moudle I made.

CircuCircu Posts: 3Member
[b][red]This message was edited by Circu at 2006-5-8 13:52:12[/red][/b][hr]
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.
[code]
#This is going to be the main part of the programe it will be resonabile for running the programe.


print " Quest For Power"
print " Made and designed By,"
print " Christopher Ross"

import Info
Player = Info.Player()


name = raw_input("Please enter you character name.
")
name = str(name)
age = raw_input("Please enter how old you are.
")
age = int(age)

print "Welcome, well let me tell you a little about this world.",name,"
"
print "Well you will being your life as a Noivce, you will be able to choose,
"
print "One of the being jobs. Which are Mining, BlackSmithing and Farming.
"
print "There are other advance jobs, but we wont go in to them yet.
"
print "After you choose your being job you will want to go to the shop of,
"
print "Your being job. The Npc there will help you along you path.
"

Mining = "Mining"
Mining = str(Mining)
BlackSmithing = "BlackSmithing"
BlackSmithing = str(BlackSmithing)
Farming = "Farming"
Farming = str(Farming)

JobChoice = raw_input("Please choice you beging job!
")
JobChoice = str(JobChoice)

if JobChoice == Mining:
print "You have choosen mining as you being job, go see the mining npc for,"
print "Some new Quest."
elif JobChoice == BlackSmithing:
print "You have choosen Blacksmithing as your being job, go see the,"
print "Blacksmithing Npc for some new quest."
elif JobChoice == Farming:
print "You have choosen Farming as your being job, go see the farming,"
print "Npc for some new quest."
[/code]
That is the main file And I am Importing the Info moudle I made.
Now this is going to be the Info Moudle script
[code]
#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,"
"
print "Your Stamina is",Stamina,"
"
print "Your Intellegnce is",Intellegnce,"
"
print "Your Rank is",Rank,"
"

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 = []
[/code]
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.


Comments

  • infidelinfidel Posts: 2,900Member
    : [b][red]This message was edited by Circu at 2006-5-8 13:52:12[/red][/b][hr]
    : 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:

    [code]
    #This is going to be the main part of the programe it will be resonabile for
    #running the programe.

    import info

    TITLE = """ Quest For Power

    Made and designed By:
    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:
    (M)ining
    (B)lacksmithing
    (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()
    [/code]

    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
    : [code]
    : #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,"
    "
    : print "Your Stamina is",Stamina,"
    "
    : print "Your Intellegnce is",Intellegnce,"
    "
    : print "Your Rank is",Rank,"
    "
    :
    : 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 = []
    : [/code]
    : 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:

    [code]
    #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)
    [/code]

    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.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • CircuCircu Posts: 3Member
    : : [b][red]This message was edited by Circu at 2006-5-8 13:52:12[/red][/b][hr]
    : : 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:
    :
    : [code]
    : #This is going to be the main part of the programe it will be resonabile for
    : #running the programe.
    :
    : import info
    :
    : TITLE = """ Quest For Power
    :
    : Made and designed By:
    : 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:
    (M)ining
    (B)lacksmithing
    (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()
    : [/code]
    :
    : 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
    : : [code]
    : : #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,"
    "
    : : print "Your Stamina is",Stamina,"
    "
    : : print "Your Intellegnce is",Intellegnce,"
    "
    : : print "Your Rank is",Rank,"
    "
    : :
    : : 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 = []
    : : [/code]
    : : 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:
    :
    : [code]
    : #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)
    : [/code]
    :
    : 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.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :
    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.
  • infidelinfidel Posts: 2,900Member
    : 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.

    Glad I could help.

    Modules don't *have* to be in lowercase, it's just a convention.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.