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

  • SEARCH
  • Home
  • 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 6567869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:16+00:00 2026-05-25T14:23:16+00:00

I’m developing video game, and I’d like it to be highly modable. Currently, all

  • 0

I’m developing video game, and I’d like it to be highly modable. Currently, all my game logic is defined in Python, my engine logic in C++, and my data in XML. I’d like to explain to you how an entity is defined in my game and listen to what you think; for example, is it too verbose?

First, some background:

  • Entities are made out of components (component-based entity model).
  • Components can be of two types: Attributes and Behaviors.
  • Attributes are just ‘dumb’ data. They are things like health, speed, etc.
  • Behaviors define how the entity interacts with its Attributes, the world, other entities.

Defining an Attribute

I’ll go over this piece by piece. First I’ll explain how to define an Attribute. In Python, and Attribute might look something like this:

class Life(Attribute):
    def __init__(self):
        # Default values
        self.health = 100
        self.toxicity = 0 

Pretty basic. Now, in the XML file, each field in the Attribute can be given a different value for each entity we define:

<Attribute>
    <Name>life</Name>
    <Class>hero.attributes.Life</Class>
    <Field>
        <Name>health</Name>
        <Value>100</Value>
    </Field>
    <Field>
        <Name>toxicity</Name>
        <Value>78</Value>
    </Field>
</Attribute>
  • Name — an identifier for the attribute (kinda like objects in Python). Will be useful when we define Behaviors.
  • Class — the Python class of this attribute.
  • Field — a field of the attribute.
  • Field.Name — must be the same as the Python field (‘self.health’ → ‘health’).
  • Field.Value — value of this field.

Defining a Behavior

As I’ve said earlier, Behaviors interact with the entity’s Attributes. For example, the Damage Behavior below needs to know about the Life Attribute.

class Damage(Behavior):
    def __init__(self):
        self.life = None

The XML code for setting up a Behavior is similar to that of an Attribute, but not identical:

<Behavior>
    <Class>hero.behaviors.Damage</Class>
    <Attribute>
        <Field>life</Field>
        <Link>life</Link>
    </Attribute>
</Behavior>
  • Class — Python class of the Behavior;
  • Attribute.Field — the field of the Behavior where the reference to the Attribute is to be placed
  • Attribute.Link — what Attribute to link to. Must be one of the value in the Name tags of the Attributes defined above.
  • 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-25T14:23:17+00:00Added an answer on May 25, 2026 at 2:23 pm

    Have you considered using json instead of XML? It is less verbose, more readable, and can be converted into a ready-to-use Python data structure:

    For example:

    import json
    
    x='''{"Field": [{"Name": "health", "Value": 100}, {"Name": "toxicity", "Value": 78}],
        "Name": "life",
        "Class": "hero.attributes.Life"}'''
    
    attribute=json.loads(x)
    
    # {u'Class': u'hero.attributes.Life',
    #  u'Field': [{u'Name': u'health', u'Value': 100},
    #             {u'Name': u'toxicity', u'Value': 78}],
    #  u'Name': u'life'}
    

    And to convert the dict back into json,

    attr=json.dumps(attribute)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.