Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Deleting Events

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Deleting Events Page: [1]
Login
Message << Older Topic   Newer Topic >>
Deleting Events - 3/3/2021 10:38:46 AM   
jkgarner

 

Posts: 174
Joined: 4/30/2020
Status: offline
When writing Discrete Event Simulations, executing events often create subsequent events in a chain of events that mimic behavior, then events that are fired are generally destroyed upon firing. I have done this for many years across many simulations in several languages.

As I am writing events in Command, I am finding that I am writing chains of events.
e.g.
EventA on unit X, is followed by EventB on unit X, then EventC on unit X.
The same series happens on several other units, as well.
Other series of events happen on the units as well.

As there are variable times between the events, and these times can be significant, several series may interleave so the exact execution of events is never guaranteed, not consistent across runs, however the following is always true:
EventA on unit X is ALWAYS followed by EventB on unit X, which is always followed by EventC on unit X.

All this is true for all Discrete Event Simulations.

Technically, I could generate all the events in the series, and throw them at the system, however, since the times are variable, I would prefer to generate the events in sequence in a chain: let EventA generate EventB, and let EventB generate EventC (and so forth)

Ideally, I would like to delete the events as soon as they are executed, to keep the system clean, so I have built a test with several units that are all running a series of events. Each event in the series has a small script that calls a function. Though the functions are distinct and different, each function, does the following: delete the event (trigger and action) that fired to call the function, modify the state of the unit in the desired manner, generate an event (trigger and action) to cause an event to fire for the subsequent event in the chain. I even have a function (We shall call 'ScriptUnit' in the discussion) that I call to generate the first event, and store information about the subsequent events as KeyValues. This all seems fine and dandy. All the code loads in, every function has been tested and works as described. The scripts that are generated to call the functions have been tested in the console and function as described on all the units. However, as soon as I try to get them to execute as events (not from the console) ONLY the first event of the first unit called by ScriptUnit is fired. All the other events appear in the GUI, with their triggers and actions. Everything is in place, but ONLY the first event of the first unit works as expected. After that event fires, the second event for the first series appears with its trigger and action. And it will fire at the appropriate time. But nothing else works. If I change the order of the calls to ScriptUnit, then a different unit's events will function, specifically the first unit called by ScriptUnit. The others are loaded into the system and appear in the GUI, but are not fired.

So the first question is: Can I reliably delete an event while executing the function triggered by the event? My whole coding structure is dependent upon this being the case, and looking through the forums, some seem to be of the opinion that this might not work.

The second question is: what is different about the Lua memory space and execution space when executing an event vs. executing from the console? Print statements are disabled, for example. Error reporting is different... Are there recommendations on how to code 'properly' for events vs the console? Clearly, I must trap my errors, and strongly consider using pcall if a ScenEdit.. function call could fail. Are there other recommendations that I should follow?

The third question is, how do I test my event code? Manually running events is a very slow way to test, and does not allow me to automate my testing.

The final question is what might cause the described behavior in my system?

Any thoughts?
Post #: 1
RE: Deleting Events - 3/3/2021 12:08:11 PM   
KnightHawk75

 

Posts: 1352
Joined: 11/15/2018
Status: offline
At the risk of responding without adding much or helping at all.
On #1 If not could just queue up the deletes and have a watchdog event clean up the events every X amount of time.
On #2 The only thing I can think to remind about is testing things in the console with Tool_EmulateNoConsole(true) while building events as it should better represent how things will act under real event execution environment, as you mentioned, sometimes there may be a difference in expected results due to err suppression.
On #3 Fair question, I got nothing for you.
On #4 hmm I need to chew on it more and try replicating something similar before speculating on that.




(in reply to jkgarner)
Post #: 2
RE: Deleting Events - 3/3/2021 12:34:57 PM   
jkgarner

 

Posts: 174
Joined: 4/30/2020
Status: offline
Yeah, I threw a lot out there.

I would like a definitive answer on #1, as it will radically alter my approach if it is not possible.

Re #2: I had forgotten about that function, until you mentioned it. I need to incorporate that in my manual test code, so that I don't forget to call it.

I'll keep thinking about #3, as I really wand full test coverage on my code, especially the event code that is so dynamic.

Re #4: if #1 is not possible, it may be that the deletion of a running event somehow craps on the event driving system within Command. My next step is to refactor the code (delete the previous event instead of the current event) to see if things work better. It would be quicker and easier to build the 'watchdog' event, but polling can be very expensive... An easy test is to simply comment out the deletion code, allowing the events to build up, and see what happens. If this fixes things then it is the concurrent deletion that is the problem.

I appreciate your thoughts.

(in reply to KnightHawk75)
Post #: 3
RE: Deleting Events - 3/5/2021 2:17:39 AM   
jkgarner

 

Posts: 174
Joined: 4/30/2020
Status: offline
To answer the first questions:

I've hooked the code up to delete the events from the scritp called by the event...
Once I had all my scripts CORRECT, everything worked like a charm. I see no issues with deleting events from the code triggered by the event.

I still would like to figure out a way to unit test the event code in an automated fashin, instead of this piecemeal stiff I've been forced to do.

(in reply to jkgarner)
Post #: 4
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Deleting Events Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.237