Book a Demo

Author Topic: Create object in simulation  (Read 3462 times)

adeebulhafiz

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Create object in simulation
« on: April 14, 2022, 11:11:13 pm »
While following the Model simulation Tutorialhttps://sparxsystems.com/enterprise_architect_user_guide/15.2/model_simulation/create_objects_in_a_simulation.html#:~:text=Create%20Object%20Using%20JavaScript.
I am having issues.
The first thing is that I am unable to create an Object and use it's operation, everytime I reference it it says that "sim.ObjectName.operation is not a function". I am not sure exactly what am I doing wrong.
The classifier and action are in same package at same hierarchy level.
Steps I followed.
1. Create a classifier with two attributes x,y and one operation add.
2. Edit the behavior of add to:
Code: [Select]
this.x=x;
this.y=y;
return x+y;
3. Create an action in an Activity Diagram, and use effect field of the action to create object using JS as given in tutorial.
4. in the effect of next action element,
Code: [Select]
this.result = this.ObjectName.add(7,7);
5. Final element.
6. Run simulation with Action2 as breakpoint, to observe local window.

Once the code pauses and when Action2 gets executed in the next step. It throws error that "...add is not a function". I am not sure what I am doing wrong.

I have also initialized the attributes while defining them.
I have also tried initializing the attributes before passing anything to the "operation" in Action2.

I would appreciate the reply.

Edit:
My EA level: Beginner
EA version: 15.2 Unified Edition
« Last Edit: April 14, 2022, 11:16:43 pm by adeebulhafiz »

adeebulhafiz

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Create object in simulation
« Reply #1 on: April 14, 2022, 11:23:25 pm »
Okay This is strange. I had tried this earlier but it didn't work at that moment.
Just so that new beginner like me doesn't go through this.

I just dragged the classifier to the Activity Diagram, and voila everything works.  :)
But if EA support is watching this. It would be nice that they add it to the documentation.

However this in general doesn't seem right. If JS could create an Object, why do I have to create an Instance of the classifier by dragging it to the diagram. In this case what's the use of "CreateObject" function?