Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Text based Game
#1
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 = actor
I 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!
Reply
#2
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 = self
Is actor another class?
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Color a table cell based on specific text Creepy 11 2,008 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,529 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,039 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Extract text based on postion and pattern guddu_12 2 1,643 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  A text-based game [SOLVED] Gameri1 6 3,920 Apr-20-2021, 02:26 PM
Last Post: buran
  OOP vs functional - - elaborate turn based RPG game (Derek Banas Udemy course again) Drone4four 6 3,945 Mar-14-2021, 08:38 AM
Last Post: ndc85430
  how to make a hotkey for text adventure game myn2018 2 1,979 Jan-06-2021, 10:39 PM
Last Post: myn2018
  Winning/Losing Message Error in Text based Game kdr87 2 3,008 Dec-14-2020, 12:25 AM
Last Post: bowlofred
  Split gps files based on time (text splitting) dervast 0 1,893 Nov-09-2020, 09:19 AM
Last Post: dervast
  name error with text based rpg code cris_ram415 4 2,436 Oct-25-2020, 05:44 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020