Replies: 8 comments 4 replies
-
Assignment of global variable should be implement in the parent state machine by event that was send from invoked machine invoke_global.mp4P.S. And for such very simple case I am not sure that you need invoked machines invoke_global_simple.mp4 |
Beta Was this translation helpful? Give feedback.
-
Wow, thank to so much for your support. That makes a lot of sense to send an event from the child to the parent. Here a few questions though:
Is there a trick around that error? |
Beta Was this translation helpful? Give feedback.
-
Cool! Yes, that works. I didn't see there is a special XML Test field as well. The ScxmlEditor is a very powerful tool! It needs a bit of learning but then it's awesome. Thanks! |
Beta Was this translation helpful? Give feedback.
-
When changing to invoked statemachines I came across another question/problem ... Are states from the parent (or full hierarchy) known inside the invoked statemachine? It seems the statemachine in my case is stuck in StateShape10 so the In() doesn't seem to work. |
Beta Was this translation helpful? Give feedback.
-
I see. So, invokes are like function calls and they only know their local scope. Just a random thought ... When I was writing xml scxml in qt by hand before knowing the ScxmlEditor existed I noticed that invoked statemachines didn'twork properly in qt because qscxmlc gives you an error if you include the same statemachine more than once (at least in qt <=5.7). The way I solved this was by pasting the scxml block I needed to duplicate into a script and then replicating it n number of times of course changing id's and names of events so everything stays unique. The generated scxml block I pasted back into the original scxml. Painful, but it worked. I could envision a different way of doing this: Take for instance your "Unoptimized statechart without invoke" example you have here . If you make a change to one of the 4 blocks you have to change the other 3 the same way. So, in situations where you have to be in the scope of the entire statechart and can't use an invoke you could have a new feature which treats one of the 4 blocks as master and the other 3 as a clones. State names like On_1, On_2, On_3,... would need to be defined as On_$ and $ will be replaced when ScxmlEditor dynamically expands the code during runtime into 4 unique blocks. The master could be kept in a separate scxml file and instead of an "invoke" you have to use a "clone" element. Does that kind of make sense? Do you think that would be a useful feature others would be interested in? The other way to see that is having a special "invoke" which is instead of instantiating it flattens out the scxml and so it stays within the scope of the overall statechart. |
Beta Was this translation helpful? Give feedback.
-
Here is an example with setting global variables with extended GetGlobal and SetGlobal functions get_set_global.mp4<scxml datamodel="luavia" name="ScxmlChild" version="1.0" xmlns="http://www.w3.org/2005/07/scxml">
<state id="child">
<onentry>
<script>i_global = GetGlobal('GlobalVar')
i_global = i_global + 1
SetGlobal('GlobalVar', i_global)
</script>
</onentry>
<transition target="FinalShape1"/>
</state>
<final id="FinalShape1"/>
</scxml> |
Beta Was this translation helpful? Give feedback.
-
I have a couple of projects on Raspberry and my workflow is the next:
Unfortunately I don't have ready-to-use examples in combination of Qt and uscxml. Only through my UscxmlCLib for educational purposes. Does that work for ecmascript as well? This class is passed to state machine and its methods are used there |
Beta Was this translation helpful? Give feedback.
-
I have currently something like this where I track key presses
I thought I replace it with a state machine which I invoke to make it easier since I needs about 20 of these.
And the corresponding invoked state_machine looks like this:
The variable VarKeyState keeps track the state of all keys e.g. 0000000010101110 (every bit is one of the keys)
Unfortunately, the invoked state machine does not know the variable VarKeyState
Any idea how to get access to a global variable from inside an invoked state machine?
Beta Was this translation helpful? Give feedback.
All reactions