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
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:
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
If no state id is given, I have the special case that the initialstate attribute of
Now this is possible:
This will enable me to create some common states that can be shared among different units (such as idle, die, ...).