Book a Demo

Author Topic: State Machine - Logger example questions  (Read 4411 times)

idlehanzgray

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
State Machine - Logger example questions
« on: October 29, 2022, 03:22:32 am »
I was going through the Help and looking at the state machine use of a logger and thought that could be a helpful function. There are times that, rather than perhaps savings the states as they occur - I might want to write the value of variables, etc.

I created a simple state machine (image link below) to test the logger example. I am assuming (as the great body of evidence will show) - that I am stoopit. This state machine reflects that.

In the initial state I set a counter and then use the example code from the help to create my logger. So far, so good. Although I do have a question - is something supposed to happen with logger.Show()? I don't see anything in the console - should I be looking in the windows event viewer?

The in the next state I simply take a random shot - 90% I'm probably stoopit, else... maybe not - in this code snippet below.

if (this.stoopitChance <= 90) {
   logger.log("You are so stoopit")
} else {
   logger.log("Still stoopit... but the help could be better")
}

However, when I hit this instance of logger.log, an error is reflected in the simulation window:

[214175784]      SIMULATION ERROR: logger is undefined Expression: // chances are I'm stoopit - check if we are - log the result

Do I need to create a new COMObject? I would think not. That begs the question, how do I refer to my already instantiated COMObject?

And of course - where is the log?
How would I change this to say, write to a local text file?

https://imgur.com/DtkrdCT

Thanks all!

idlehanzgray

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: State Machine - Logger example questions
« Reply #1 on: November 11, 2022, 06:03:39 am »
I guess I should step back and ask, does anyone use COM objects with a state machine in EA?

Takeshi K

  • EA User
  • **
  • Posts: 632
  • Karma: +43/-1
    • View Profile
    • Sparx Systems Japan
Re: State Machine - Logger example questions
« Reply #2 on: November 11, 2022, 10:47:21 am »
Hello idlehanzgray,

This is not a problem that 'var'-defined variable cannot be used in the second State.
Please confirm, if you change 'var logger = new COMObject("MySim.Logger");' to ' var logger = new COMObject("Nothing.Defined");', the result will not change. That means, you failed to create the object. Maybe 'MySim.Logger' is just an example and you need your 'MySim.Logger'.

And you can use the 'Trace' to output a text to the Simulation window. e.g. Trace("You are so stoopit");

HTH,
--
t-kouno

idlehanzgray

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: State Machine - Logger example questions
« Reply #3 on: November 12, 2022, 02:52:42 am »
That was super helpful. When I first read the help example I assumed that the COMObject that was being used existed. It does not. So one needs to use a COMObjcect that exists for the creation to be successful.

Also, it never clicked for me that the purpose of the Trace command was to output to the simulation window until I saw your note. The ability to display information about the state, without having to pause and look at variable values is what I was really after.

Thanks!