Book a Demo

Author Topic: Simulation of State Machine with JavaScript - is not a function error  (Read 24621 times)

DaVos

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Hi gents

I am trying to simulate an executable state machine with java script.

The java script code that I want to simulate with EA is the following

class Operation {
 
  // Method
  Add(a,b) {
    this.a = a;
    this.b = b;
    return this.a + this.b;
  }
 
}

 // Create object
 operation1 = new Operation;

result=operation1.Add(10,10)

console.log("Addition is " + result);

For the equivalent response from the EA I did the following steps:
1. Define a Class called Operation.
2. Define an operation called Add(int, int) with the following code on the behavior
this.a=a;
this.b=b;
return a+b;
3. I drag and drop the Class as an object into the state machine and call the object as operation1:Operation
4. I create a simple state machine and call the operation on the entry of the state machine but as well as on a transition connector (code added on the effect tab)
I have used the following code variations
sim.result=sim.operation1.Add(10,10)
sim.result=sim.operation1.Add()
sim.Add(10,10)
this.Add()
etc...

The initialization of the variables a and b have been done with different ways, on the object, on the state machine on the execution analyzer script etc.

I am always get the same error : sim.Add is not a function.

Any ideas why ?

Is it a simulation configuration error ?

I can see on the local variables that the Add() function is not called and not even existed on the object.

Any help appreciated  8)

Thank you





EAButNotForGames

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
Re: Simulation of State Machine with JavaScript - is not a function error
« Reply #1 on: March 29, 2024, 12:07:59 am »
have you found a solution to this problem?