Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

SCXML enhancements

Sign in to follow this  


Wow... 2 entries in one day...

While working on my game and designing the first scxml file for the first unit, I stumbled across the fact, that some units share data and/or functionality (means states).

Now, the scxml draft states that you can insert any data within the datamodel using the src attribute of and that you can insert any part of a state model by using the src attribute of or but I didn't implement it. I mainly had 2 reasons:

1. I didn't see that it would benefit me.
2. I feared that including src would complicate a lot of my parsing code.

Well... #1 has been eliminated by above statement about my units. Leaves me #2.

I first implemented the src stuff for the datamodel. It all went quite smooth but I must admit, that I changed the behaviour a little bit. The draft states 2 things:

1. doesn't support the src attribute.
2. expr, src and subnodes are mutual exclusive. Means, you may not have a src attribute and children to the tag.

I decided that #1 is just plain stupid. If I create a datamodel which relies (as in my case) on common properties for different units, I don't want to rewrite those datamodels in every statemachine. It's true that you could do this by having a src attribute in but this would push the data down one depth into the data hierarchy. I could not directly access a value by it's name but would have to pass through the parent. Thus I added a src attribute to

I also ignore #2. The main reason here is that I want to be able to "overload" any value that I have previously added through another data source. Imagine that I have a set of data representing 10 different properties. 9 of them are the same most of the time and only one changes... You simply want to overload one property...

Ok... the result is that following is now possible in my scxml implementation.


The src attribute within or seemed a lot more complicated to me. Fortunately, it was just plain simple. I already had all the code I needed to simply load a state from another file. I only had to write the code to iterate through the xml hierarchy and find the right state if a state id is given.

If no state id is given, I have the special case that the initialstate attribute of has to be transformed into an with embedded . The rest is just simple state loading.

Now this is possible:


This will enable me to create some common states that can be shared among different units (such as idle, die, ...).

Have fun,
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!