![]() |
Python Text based Game - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python Text based Game (/thread-7143.html) |
Python Text based Game - Luoxiang - Dec-22-2017 Hello everyone. I am new to programming in general. I took up Python Because it was the language I wanted to use for this text based adventure game I wanted to make! I have however run into some issue with getting a character in the game with me. This is going to be a longer one, so bare with me. I have been succesful with adding locations to the game like this Source module: # add another location to the game def add_location(self, location ): location.game = self self.locations[location.name] = location return location def new_location(self, *args): return self.add_location(Location(*args))Then I write the location like this: # define and describe a couple of locations Infirmary = game.new_location( "Infirmary", """Test Description for first room""")Now this works. The issue im having is how to implement this: # add an actor to the game def add_actor(self, actor): actor.game = self if isinstance(actor, Player): self.player = actorI have tried this: Joebloe = game.add_actor ("joebloe" """I am not really sure :/"""So i know that you dont know what most of my variables mean without seeing the whole script. But if anyone can point me to the correct direction, like how to format the new character, or if i am going about it all wrong...that would help a lot! RE: Python Text based Game - Terafy - Dec-22-2017 With OOP you need to create and instance. Because I don't know what the class name or if it has any argument. I'm just assume you got a class called:game without any argument Joebloe = game() Joebloe.add_actor("joebloe") # add an actor to the game def add_actor(self, actor): actor.game = selfIs actor another class? |