Book a Demo

Author Topic: JavaScript variables in dynamic simulation  (Read 3637 times)

MartijnB

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
JavaScript variables in dynamic simulation
« on: March 28, 2014, 07:39:38 pm »
I am trying to create a system with multiple parallel executing state machines. For each state machine I would like to use variables which are private for that state machine. Is this possible in EA?

I have already tried constructions like these:
- Model
---Package
-----StateMachine
-------Package1
---------StateMachine_sub1
-------Package2
---------StateMachine_sub2

- Model
---Package
-----StateMachine
-------Class1
---------StateMachine_sub1
-------Class2
---------StateMachine_sub2

I would like to create a variable in “StateMachine_sub1” which is not visible in “StateMachine_sub2” and preferably also not in “StateMachine”. Unfortunately, I have not been able to create this in any way. The variables I create are always visible to the whole system. Does anyone know a solution to this problem?

P.S. Namespacing could be a solution; but then I would like to automate this. It is possible to find the parent of a state by using the scripting function of EA to be able automatically create namespaces, but I’m not able to use this in the JavaScript of the simulation. :(

MMA

  • EA User
  • **
  • Posts: 63
  • Karma: +3/-0
    • View Profile
Re: JavaScript variables in dynamic simulation
« Reply #1 on: April 22, 2014, 09:01:22 am »
Yes, it is possible in EA.

I would change the constructions like one of these:

- Model
---Package
-------Class1
---------StateMachine1
-------Class2
---------StateMachine2

This means each of the contexts(Class1, Class2) have a statemachine, so you can add a variable (e.g. m_currentState) to each of the contexts. They communicate by send/broadcast event to context.

Note:
In EA 11, you can create an executable statemachine Artifact, then drag Class1 and Class2 and drop in to the artifact as properties. Then generate code on the artifact, the environment of interaction between instance of Class1 and instance of Class2 are automatically setup for you. You can generate, build and run. Then you can see the simulation running on the diagram as a "graphic representation of the debug process".
EA 11 currently support C/C++/Java/JavaScript/C# for executable statemachine simulation.

- Model
---Package
-------Class1
---------StateMachine1
---------StateMachine2

You can imagine there is a function:  
     Class1::RunAllStatemachines()
Then the two statemachines will run separately, but the attributes defined in Class1 can be accessed/modified by transition's effect and state's behaviors from both statemachines.

- Model
---Package
-------Class1
---------StateMachine
-------------submachineState : StateMachine_sub1
---------StateMachine_sub1

This is the common way of using submachine state, you can think this as a "function call"(submachine state) to a "function definition"(statemachine).
Note:
If entryPoint/exitPoint are used in the submachine, you need to create connectionPointReference on the submachine state to map to the submachine's entryPoint/exitPoint.


Hope this helps ;)
« Last Edit: April 22, 2014, 09:14:17 am by milesma »