Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:17:37+00:00 2026-05-28T13:17:37+00:00

Im completly new to Python. Following this guide: http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod I have a simple question:

  • 0

Im completly new to Python. Following this guide: http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod

I have a simple question: When all the monsters have been created here, how does python distinguish between each instance of the class? As far as i can tell, all the instances are named “monster”.

def place_objects(room):
#choose random number of monsters
num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)

for i in range(num_monsters):
    #choose random spot for this monster
    x = libtcod.random_get_int(0, room.x1, room.x2)
    y = libtcod.random_get_int(0, room.y1, room.y2)

    #only place it if the tile is not blocked
    if not is_blocked(x, y):
        if libtcod.random_get_int(0, 0, 100) < 80:  #80% chance of getting an orc
            #create an orc
            fighter_component = Fighter(hp=10, defense=0, power=3, death_function=monster_death)
            ai_component = BasicMonster()

            monster = Object(x, y, 'o', 'orc', libtcod.desaturated_green,
                blocks=True, fighter=fighter_component, ai=ai_component)
        else:
            #create a troll
            fighter_component = Fighter(hp=16, defense=1, power=4, death_function=monster_death)
            ai_component = BasicMonster()

            monster = Object(x, y, 'T', 'troll', libtcod.darker_green,
                blocks=True, fighter=fighter_component, ai=ai_component)

        objects.append(monster)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:17:38+00:00Added an answer on May 28, 2026 at 1:17 pm

    Each object is stored at different memory location. That’s how you differentiate.

    Use the builtin function id()

    id(object) 
    Return the “identity” of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.
    

    Documentation also says

    CPython implementation detail: This is the address of the object in
    memory.

    Example:

    >>> class Foo:
    ...     pass
    ... 
    >>> x = Foo()
    >>> y = Foo()
    >>> id (x)
    17385736
    >>> id (y)
    20391336
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: completely new to Python from a PHP background Ok I'm using Python on
I'm new to Python so forgive me if this is basic, I've searched but
I have worked with ASP.NET(C#, classic/MVC), Django(Python) and CI(php) but I am completely new
Okay, I'm completely new to this. I created a python script that imports tkinter
sorry if this is an obvious question, but I am relatively new to python
Does python create a completely new string (copying the contents) when you do a
I'm trying to extend Python 3 with C++ in MSVC++ 2010. I'm completely new
I am completely new to python. I have installed it on windows. I am
Apologies, I am completely new to Django and Python. I have 2 questions. First,
I am completely new to python and I have a serious problem which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.