Giter Club home page Giter Club logo

Comments (4)

benmoran56 avatar benmoran56 commented on August 12, 2024

Sorry for not replying sooner. I didn't get notified of this issue ticket.
You can do this with the world.add_compoent method. There is a type_alias argument. For example:

entity1 = world.create_entity()
world.add_component(entity1, Lion(), type_alias=Animal)

This means that you can't add components when creating an entity. You have to do it in two steps.
A full example:

import esper


world = esper.World()

# Base class:
class Animal:    pass

class Lion(Animal):    pass

class Tiger(Animal):    pass

class Bear(Animal):    pass

entity1 = world.create_entity()
world.add_component(entity1, Lion(), type_alias=Animal)

entity2 = world.create_entity()
world.add_component(entity2, Tiger(), type_alias=Animal)

entity3 = world.create_entity()
world.add_component(entity3, Bear(), type_alias=Animal)

for ent, animal in world.get_component(Animal):
    print(ent, animal)

from esper.

jason-bowen-zheng avatar jason-bowen-zheng commented on August 12, 2024

Can I use one more type likes type_alias=(Animal, Lion)?

from esper.

benmoran56 avatar benmoran56 commented on August 12, 2024

No, that's not possible. It would be difficult to store in the DB, and difficult to query.

from esper.

benmoran56 avatar benmoran56 commented on August 12, 2024

I'm going to close this for now, but please feel free to reply if you want to discuss further.

from esper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.