Jump to content

TimeStay. lua


flytv1

Recommended Posts

Hi everyone.

I am not sure how many XPlane users are active here but just in case some may be able to use it, I posted the message from XPlane.org, here also.

This is somewhat equivalent to the Time Stay available for FSX.

 

>>

I was able to find way to get the TimeStay to work. I tried many different approaches but they all has some unwanted side effects. The script below works but it may be system dependent, some experimentation by the User may be needed.

 

I am sure there better implementations but I have a very difficult time finding documentation that gels / connects all the available information. There seem to be many gaps in the documentation that is only known / found if you already know / are familiar with the intricacies of XPlane.

 

To use copy the text below the TimeStay. lua into a text file, called TimeStay.lua or whatever you want to call it and place it into your X:....\X-Plane 11\Resources\plugins\FlyWithLua\Scripts and Start XPlane. Your Local time, as shown in teh lower right of the C172 G1000 should stay about the same. It should not affect any thing else in the way the sim operates. If Errors found, or have recommendations / suggestions, post here.

 

To disable the script you can change the extension to something like "TimeStay. lua.dis" or remove the Script from your folder / directory.

 

TimeStay. lua

 

 

 

--Move Local Time back, TimeStay within the same minute.

--Use if you only like to fly at certain times, like Sunset..

--Note: It may be system dependent change set_back= value if needed.

 

local start_time = os.clock()

local set_back = 20

 

function stay_time()

if os.clock() > (start_time + set_back) then

command_once("sim/operation/time_down")

start_time = os.clock()

end

end

do_often("stay_time()")

Link to comment
Share on other sites

  • 3 months later...

The problem with using os.clock() is that it really isn't measuring "clock" time used, it is measuring CPU time used by the program. The other problem is that as this isn't precisely resetting the time after 20 seconds, the time of day you are trying to capture will slowly drift. You could use os.time() instead, but if your goal is to reset XP to a specific time in the sim, why not manipulate XP's simulated clock.

 

A better way to do it is to capture Zulu time (Zulu time is writeable whereas local time is not) and then keep resetting that dataref to the time you captured. My code snippet looks like this:

 

local zulu_t = dataref_table("sim/time/zulu_time_sec") -- float y seconds Zulu time (seconds since midnight)

 

local time_loop = {state = 0, time = 0.0, period = 120, button = "Off", trigger = 0} -- time loop settings

 

local function time_loop_run()

 

if (time_loop.state == 0) then

time_loop.trigger = 0

elseif (time_loop.state == 1 and time_loop.trigger == 0) then

time_loop.time = zulu_t[0]

time_loop.trigger = 1

elseif (time_loop.state == 1 and time_loop.trigger == 1) then

if (zulu_t[0] > time_loop.time + time_loop.period) then

zulu_t[0] = time_loop.time

end

end

end

 

With this code, if you want to have the time loop at 06:15:00z, it will do so. I loop back to the saved zulu time every 2 minutes, no reason you couldn't stretch this out to 5 or 10 minutes to get some change.

 

I have a button configured that, when pressed, turns on the time loop, thus the use of state and button elements in the table.

 

Ian

Link to comment
Share on other sites

Hey do any of you guys know (off topic) when I choose to let the ai fly my plane, it never seems to fly very far before it lands again.

So do you know how or where the code is to alter the distance to make it fly further, I'm not talking about crossing the Atlantic but possibly from the UK to the continent may be?

 

Col.

Link to comment
Share on other sites

Hi Ian.

You are correct, there is some drift / inaccuracy associated with that Script, which typically is of no real consequence in practical use.

The good / best thing about it is that it uses very few resources and does not affect the performance overall.

Did you actually test that Script? As is, it may interfere with the default operation of other Scripts that collect Zulu... and other times?

 

The problem with using os.clock() is that it really isn't measuring "clock" time used, it is measuring CPU time used by the program. The other problem is that as this isn't precisely resetting the time after 20 seconds, the time of day you are trying to capture will slowly drift. ...

Ian

Link to comment
Share on other sites

Hi.

I do not know what algorithm LR uses for AI, but it looks like there are preset sequences, it repeats itself, and it only changes if there is something affecting it, like something that may interfere with the landings, collisions...

 

Hey do any of you guys know (off topic) when I choose to let the ai fly my plane, it never seems to fly very far before it lands again.

So do you know how or where the code is to alter the distance to make it fly further, I'm not talking about crossing the Atlantic but possibly from the UK to the continent may be?

 

Col.

Link to comment
Share on other sites

Using os.clock() with a variable of 20, along with using the time_down command, which on my system varies between 40 and 75 seconds (it isn't an exact amount), contributes to a fair amount of drift on a 2 hour+ flight, I like that I can reset it it to an exact time.

 

Changing the time in the sim either by my script or using the time_down command affects the clock regardless as both change the time, so if someone is using zulu/local for a timer, it will get messed up, better to use sim/time/total_running_time_sec as a counter for any timers.

 

Hi Ian.

You are correct, there is some drift / inaccuracy associated with that Script, which typically is of no real consequence in practical use.

The good / best thing about it is that it uses very few resources and does not affect the performance overall.

Did you actually test that Script? As is, it may interfere with the default operation of other Scripts that collect Zulu... and other times?

Link to comment
Share on other sites

Hi Ian and everyone.

I originally tried Zulu and a couple of other clocks and for what / how I wanted to use the Script I found the os.clock to be a best compromise.

If anyone has a a better idea post it here.

Below I included a version that uses Zulu time in case anyone is interested.

 

--To use, copy the contents from --Start to --End into a file called "AnyName.lua" save it as a pure text with extension ".lua".

 

--Start

--TimeStayZ.lua file name I used.

--The Script starts automatically when a situation is loaded / XP starts.

--Move Zulu Time back, TimeStay within the same minute +60 sec.

--Use if you only like to fly at certain times, like Sunset..

--Using Zulu time, instead of os.clock is more accurate / less system dependent, but more resource intensive.

--Change "set_back =" value if other than 60 sec. period is desired.

--Default "start_time" is your selected time when the flight starts and unlike the os.clock Script it will NOT change the time using L key.

--Place it in ...\X-Plane 11\Resources\plugins\FlyWithLua\Scripts

 

--Active code Starts below:

 

local zulu_t = dataref_table("sim/time/zulu_time_sec")

-- float y seconds Zulu time (seconds since midnight)

 

local start_time = zulu_t[0]

local set_back = 60

 

function stay_time()

if zulu_t[0] > (start_time + set_back) then

zulu_t[0] = start_time

start_time = zulu_t[0]

end

end

do_often("stay_time()")

--End

Link to comment
Share on other sites

A couple of notes:

 

- This script is no more resource intensive than your original script, it is accomplishing the same thing of setting the sim's clock back X number of seconds, the difference between modifying a dataref and using an XP command is a couple of bytes of memory from a resource perspective. In fact this script, when using '60' as the period, executes less often than using '20'...

 

- You don't need to do the "start_time = zulu_t[0]" line in the function as start_time already contains the value of zulu_t as set when you defined the variable.

 

One thing you may want to look into is setting this up as a macro so that you can enable and disable the script any time you want, not too hard to do.

 

Ian

Link to comment
Share on other sites

Here is an example of using a macro. You can enable and disable the code via the FWL macro menu...

 

local zulu_t = dataref_table("sim/time/zulu_time_sec")

local start_time = zulu_t[0]

local set_back = 60

 

timeloop = false

 

function stay_time()

if (timeloop) then

if (zulu_t[0] > start_time + set_back) then

zulu_t[0] = start_time

end

else

start_time = zulu_t[0]

end

end

do_often("stay_time()")

 

add_macro("timeloop", "timeloop = true", "timeloop = false", "deactivate")

Link to comment
Share on other sites

Hi Ian.

My use of XP11-1120 is very limited. I only use it for IFR practice, and very rarely.

I find it very limited when it comes to using it as an instructional tool for VFR training.

It's during Sunset with low clouds, or IMC. In the VFR / sunset I start it and it stays there within that 60 seconds time.

In IMC is basically the same time window, but others may find the ability to enable / disable it at different / any times useful, the above Script should work for them.

 

One thing I was not able to accomplish using LUA is to start a session with the "hialt" selection for Sky color, it seems to default to "mount" and I found no way around it. Do you know of a way to do that?

Thanks.

Link to comment
Share on other sites

Hi Ian.

These are choices you can select in Developer>Sky color menu in XP. It sets mount:=1, and I think that is one type of Colors available. If you set the hialt=1 the colors of the sky change.

My goal is to have the XP colors default to "hialt" but I cannot make it stick, every time XP11 starts it defaults to "mount", regardless of the Situation I save with "hialt" on or not.

Link to comment
Share on other sites

Yup, the saved situation function of XP doesn't save everything, for example weather is not saved properly, even the date gets messed up, as does many other settings.

 

Can't see a way to change sky colours via a lua script either...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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