Jump to content

Function collision in export env


Recommended Posts

 My apologies if this has already been discussed, I attempted to search the forums but got a mile long list just using "export" as a keyword and no results trying to narrow it down.

 

The apparent convention for loading export scripts in DCS is to use WriteDir\Scripts\Export.lua as a communal loader. Various sources ( Tacview, SRS, LotATC etc ) all add a line to load their specific export script into the export environment..

 

local Tacviewlfs=require('lfs');dofile(Tacviewlfs.writedir()..'Scripts/TacviewGameExport.lua')
local TheWayLfs=require('lfs'); dofile(TheWayLfs.writedir()..'Scripts/TheWay.lua')
pcall(function() local dcsSr=require('lfs');dofile(dcsSr.writedir()..[[Mods\Services\DCS-SRS\Scripts\DCS-SimpleRadioStandalone.lua]]); end,nil)

 

The code loaded for Tacview, TacviewGameExport.lua, implies that the scripts loaded by Export.lua are loaded sequentially into the same environment ( IE: all sharing the same global space ), rather than having loading functions that provide a sandboxed copy of the export environment for each load.

 

			do
				local PrevLuaExportStart=LuaExportStart;

				LuaExportStart=function()

					tacview.ExportStart()

					if PrevLuaExportStart then
						PrevLuaExportStart();
					end
				end
			end

 

Prior to creating its own LuaExportStart function it saves the variable locally. Then at the end of its own code, upon a previous version existence returning true, executes the previous code. This "daisy chaining" of export scripts into the same global space, while risky and completely reliant on creators of these scripts to pay close attention on not trampling others ( in start, stop, and the coroutine table ), does work. Except, from what I can see, for one export function..

 

function LuaExportActivityNextEvent(t)
	local tNext = t

-- Put your event code here and increase tNext for the next event
-- so this function will be called automatically at your custom
-- model times. 
-- If tNext == t then the activity will be terminated.
	tNext = tNext + 1.0

 

This function appears to be the analog to timer.scheduleFunction() in the mission environment. The timer will repeat based on the returned time value from the function it executes. A function that relies on context based return values cannot be daisy chained as described above.

Scenario: Scripts 1 creates this function with a +1 return value, then script 2 wraps function 1 with a +5 return, and finally script 3 wraps function 2 with a +10 return.

All functions will execute as essentially one chunk at the +10 frequency returned by script 3. Causing anything time sensitive from scripts 1 and 2 to fall behind, or fail completely.

Am I missing something? Is there another way to go about this, or is this an oversight in the API? I see no way to return time values for multiple contexts via the one function call.

 

And yes, I'm aware I could use LuaExportAfterNextFrame(), as many do. However, that would be orders of magnitude faster than I need, creating an egregious amount of unnecessary network traffic adding latency to the queue. If needed I can create a global variable counter and only send traffic once the counter reaches a certain value, but the above function is perfectly suited to my task, if it doesn't risk collision with others.  

 

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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