Jump to content

Displaying "Time Since Flag" in a message


FourSpeed

Recommended Posts

Hi guys,

 

Quick one for you... I know how to trigger something when "Time Since Flag" equals or passes a certain value.

 

What I'd like to do (and can't see how in M.E.) is put out a message showing exactly what the value currently is for "Time Since Flag" for a particular flag...

 

So, say Flag 100 is set due to some condition. When some other condition occurs, I'd like to show in a message what the actual "Time Since Flag" value currently is for flag 100... For instance, if flag 100's value is 342 when the second condition triggers, I'd like to put out a message like

 

"Elapsed Time: 5 minutes, 42 seconds..."

 

I'm guessing that might need a small script, and if so, I'd greatly appreciate it if one of the scripting gurus could give me some insight on how to do it...

 

 

Thanks In Advance,

4 ~S!~

Link to comment
Share on other sites

  • 2 weeks later...

Nobody??? Really?

 

...and here I was thinking this would be a simple one -- I had no idea that it's (evidently) impossible...

 

Surely, MIST or MOOSE can retrieve the time value since a flag's state changed?

 

I'm more than a bit perplexed that there are no replies to this thread. I'd hoped that one of the scripting guru's here could point the way, or add a simple DO Script snippet to do the job.

 

<scratching head>

 

 

4

Link to comment
Share on other sites

Scripting engine doesn't know when you set a flag.

 

Generally you'd store a time value via timer.getTime() and then reference that at a later point. Suppose if you really wanted to use flags for that you could use...

 

local val = math.modf(timer.getTime())

trigger.action.setUserFlag(whatever, val)

 

Then at a later point if you wanted to check how much time has gone by.

 

local timeSince = timer.getTime() - trigger.action.getUserFlag(whatever)

 

 

The value would be in seconds so you'd need to convert it the old mathematics way.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Scripting engine doesn't know when you set a flag.

 

Generally you'd store a time value via timer.getTime() and then reference that at a later point. Suppose if you really wanted to use flags for that you could use...

 

local val = math.modf(timer.getTime())

trigger.action.setUserFlag(whatever, val)

 

Then at a later point if you wanted to check how much time has gone by.

 

local timeSince = timer.getTime() - trigger.action.getUserFlag(whatever)

 

 

The value would be in seconds so you'd need to convert it the old mathematics way.

 

Thanks, Grimes...

That gives me some helpful avenues to explore. The conversion math is trivial, finding the time value was the stumper for me.

 

Hopefully, this will get me going in the right direction.

 

 

You need scripting for this. Set up a Scheduler to check for the 2 conditions. Rough example:

 

if flag `100` == true then
   if condition 2 == true then
      time since flag `100` message
   end
end

 

There's no doubt that the solution needs some scripting... the problem for me, and with your example (if I understand it correctly) is I can't get the actual time value itself.

 

Currently, the only ME way I know is (largely) worthless:

 

Time Since Flag (100, 120) --> Message To All ("Elapsed Time -- 2:00 Minutes",10)

Time Since Flag (100, 180) --> Message To All ("Elapsed Time -- 3:00 Minutes",10)

... etc.

 

which, of course is a Terribad approach if you want the time to the nearest second or so (hence my asking in this post).

 

I think Grimes' post is closer to what I need, if I can capture the local time in a variable when the flag gets set, and I can do the same in a different variable when the second condition occurs, then, calculating the difference between the two and putting that value in a message is exactly what I'm looking for, and I just need the script snippet to print the final message.

 

 

Thanks to both of you for your responses. It is very much appreciated.

 

 

Regards,

4 ~S!~


Edited by FourSpeed
Link to comment
Share on other sites

  • 2 weeks later...

As a follow-up, in case anyone else is looking for the solution, Grimes' idea works very nicely. (Thanks!)

 

Basically, to track exact time since a particular flag, or more generically between any two triggered "events" in a mission you need the following script snippets:

 

Event #1 Occurs / Or Flag X gets set (Note: these can be done simply with normal M.E. triggers and Flag options - We just need the script snippets to find the actual Time):

  Do Script:
       startTime = timer.getTime()

Event #2 Occurs / Or determine the time (in seconds) since Event #1 / Flag X set

  Do Script:
       finishTime = timer.getTime()

Calculate Time Between Events 1 & 2 / Or Time since Flag X was set:

  Do Script:
       elapsedTime = finishTime - startTime          ###  Total Seconds between
       elapsedMin = math.floor (elapsedTime / 60)    ###  Whole Minutes between 
       elapsedSec = elapsedTime - (elapsedMin * 60)  ###  Extra Seconds after Minutes

You can, of course, display that time (as Total Seconds, or Minutes:Seconds using a normal

trigger.action.outText command.

 

 

I'm including a very simple test mission to illustrate how these work for anyone interested.

 

A couple "oddities" I noticed:

 

1> The startTime and finishTime needed to be Global variables, otherwise, when I got around to doing the Elapsed Time calculation in Snippet #3, they'd gone out of local scope. The elapsed time calculations probably also need to be global as well -- IF -- you plan to use them later. In my case, once calculated and displayed, I no longer needed them, so they could just be local in Snippet #3.

 

2> timer.getTime() returns Mission Time (time since started) in seconds to 3 decimal places. Oddly, however, in my test mission, Snippet #1 *always* returned a time value of X.001 seconds, and Snippet #2 *always* returned a time value of Y.701 seconds.

So Elapsed Time was *always* Z minutes, z . 7 seconds... Weird....

 

 

Still, those worked well enough for what I needed, so once again, Thanks to Grimes for pointing me in the proper direction!

 

Regards,

4 ~S!~

TimeTest_01.miz


Edited by FourSpeed
Link to comment
Share on other sites

As a follow-up, in case anyone else is looking for the solution, Grimes' idea works very nicely. (Thanks!) ...

 

Thank you both ... this goes straight onto the ME tips file :thumbup:

 

For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra

For Gaming: 34" Monitor - Ryzen 3600X - 32 GB DDR4 2400 - nVidia GTX1070ti - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar - Oculus Rift CV1

Mobile: iPad Pro 12.9" of 256 GB

Link to comment
Share on other sites

 

A couple "oddities" I noticed:

 

1> The startTime and finishTime needed to be Global variables, otherwise, when I got around to doing the Elapsed Time calculation in Snippet #3, they'd gone out of local scope. The elapsed time calculations probably also need to be global as well -- IF -- you plan to use them later. In my case, once calculated and displayed, I no longer needed them, so they could just be local in Snippet #3.

 

2> timer.getTime() returns Mission Time (time since started) in seconds to 3 decimal places. Oddly, however, in my test mission, Snippet #1 *always* returned a time value of X.001 seconds, and Snippet #2 *always* returned a time value of Y.701 seconds.

So Elapsed Time was *always* Z minutes, z . 7 seconds... Weird....

 

1. Timing stuff like this really is best used primarily with a single script that can be executed with local variables.

 

local tData = {}
function timeCheck()
  if whateverCondition == true then
     tData.startTime = timer.getTime()
  end
  if whateverStopCondition == true then
    tData.endTime = timer.getTime()
  end 
  if endTime then 
     --- do your code to display it
  else -- keep checking
      timer.scheduleFunction(timeCheck, {}, timer.getTime() + 0.1) -- runs at tenth of second.
  end 
end

 

Just gotta call timeCheck whenever you want to start it and maybe add some code to set tData back to an empty table.

 

2. Triggers are executed at a set rate of once a second. So that makes sense, gotta do as stated above with scripts to make it run faster.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...