Jump to content

Recommended Posts

Posted

On our dedicated servers I haven't been able to get this to work. I've got the option selected to automatically save the .sav file upon mission restart or end but it's not saving.

base-menu-window.png

  • 3 weeks later...
Posted
On 4/15/2025 at 4:24 PM, BIGNEWY said:

world.setPersistenceHandler(name, handler)

Registers a handler for generating persistent data when saving simulation state.
Name MUST conform to the same restriction described above.
Handler MUST be a Lua-function which takes no arguments and returns persistent data as a Lua-value (boolean, number, string, table).
The returned value must be JSON-serializable.

The handler will be called every time the simulation state is being saved.

I have set up a bare bones test script to test the API. It seems that with the current release (in SP), the handler is NOT invoked, even though a new miz file is created.

Here's the script that sets the handler and expects being invoked when I choose "SAVE MISSION".

Spoiler

dcsCommon = {}
dcsCommon.version = "0x"
-- 
-- DCS Persistence support 
--
function dcsCommon.hasSaveData()
    return dcsCommon.saveDataAvailable
end

-- save handler
function dcsCommon.saveHandler()
    trigger.action.outText("+++\n+++ INVOKED SAVE DATA\n")
    local msg = "this is serilizable"
    return msg -- return non-null data 
end

--
--
-- INIT
--
--
function dcsCommon.init()
    -- see if save data is available 
    local sd = world.getPersistenceData("dcsCommon")
    if sd then 
        dcsCommon.saveDataAvailable = true 
        trigger.action.outText("sd is <" .. sd .. ">, non-null", 30 )
    else 
        dcsCommon.saveDataAvailable = false 
        trigger.action.outText("dcsCommon: clean start.", 30)
    end 
end

    
-- do init. 
dcsCommon.init()

-- detect if miz was previously saved 
if dcsCommon.hasSaveData() then 
    trigger.action.outText("+++\n+++ S A V E 😧 this mission starts from a saved state.\n+++\n\n", 30)
end

-- hook into state saving to provide save data
world.setPersistenceHandler("dcsCommon", dcsCommon.saveHandler)
trigger.action.outText("world.setPersistenceHandler set for dcsCommon", 30)

What am I doing wrong (demo miz attached for reference)?

Thank you for any help.

 

invoker test.miz

  • ED Team
Posted

@cfrag

Check your log for errors you may see something like this for clues. 

 182.246 DEBUG   LuaGUI (Main): --saveMissionTo--    C:\Users\xxx\Saved Games\DCS\Missions\SaveTest.miz    nil
  182.249 ERROR   Lua::Config (Main): Call error world.runPersistenceHandlers:[string "dcsCommon = {}..."]:12: Parameter #2 (delay) missed
stack traceback:
    [C]: ?
    [C]: in function 'outText'
    [string "dcsCommon = {}..."]:12: in function 'handler'
    [string "Scripts/World/PersistenceHandlers.lua"]:16: in function <[string "Scripts/World/PersistenceHandlers.lua"]:14>. 

this is where it is in the code

function dcsCommon.saveHandler()
    trigger.action.outText("+++\n+++ INVOKED SAVE DATA\n") -- <---- HERE!!!
    local msg = "this is serilizable"
    return msg -- return non-null data
end 

 

smallCATPILOT.PNG.04bbece1b27ff1b2c193b174ec410fc0.PNG

Forum rules - DCS Crashing? Try this first - Cleanup and Repair - Discord BIGNEWY#8703 - Youtube - Patch Status

Windows 11, NVIDIA MSI RTX 3090, Intel® i9-10900K 3.70GHz, 5.30GHz Turbo, Corsair Hydro Series H150i Pro, 64GB DDR @3200, ASUS ROG Strix Z490-F Gaming, PIMAX Crystal

Posted
15 minutes ago, BIGNEWY said:

this is where it is in the code

Huh. Now if that doesn't show me as a complete fool! No excuses, I should also have investigated the logs before jumping to conclusions. I stand corrected, thank you BN! 

Posted
43 minutes ago, BIGNEWY said:

this is where it is in the code

Leaving aside my gaffe at not checking the logs, I believe it would help if the code that is invoked has the ability to use the DCS debug feature (using setErrorMessageBoxEnabled(true) ). Invoking the handler with all debug options turned off (and not being able to turn it back on as it seemingly is implemented now) makes developing code for this feature even more bothersome than it already is. So, please allow script authors to turn debugging on in the invoked code. I also recommend that the documentation mentions that the invoked code has all debugging turned off, as simple-minded coders like I might expect the same scope being active as the rest of the code (I usually code with debugging on).

  • 2 weeks later...
Posted

it seemed the saved state function offered the possibility of missions starting from road bases. 
Unfortunately if I make a simple mission with a player Su-25 & land on a road, then use the save state function, exit and load the saved mission, the aircraft won’t be on the road, it will be on a parking space at the nearest airport. 
Is this the intended behaviour or a bug caused by an unexpected use case ?

 

Cheers.

  • 2 weeks later...
Posted
On 5/3/2025 at 9:29 PM, DragonSoulkin said:

On our dedicated servers I haven't been able to get this to work. I've got the option selected to automatically save the .sav file upon mission restart or end but it's not saving.

 

On 5/4/2025 at 3:39 AM, DragonSoulkin said:

Manually clicking "Save State as..." and saving from there also crashes the server.

So far, I have yet to have it spit out an autosave, no matter what I do. I am going to try setting a end mission value and see if that does anything.

 

A little feedback. I am not the current use case, as I am trying to code a dynamic server, but here is my feedback. I find myself wishing I could have it not save any unit in the air is saved because my end goal as a server would be for something that was killed for it to not be there next time the server runs. 

 

One bug I did notice was that AI units that are in the air tend to be put on the ground, and then they try to take off from the ground? But I have also had situations where a Ai plane was taxing and the save started it at a parking spot facing the wrong way. But once again, it just tried to take off right from where it was.

  • Thanks 1
  • Recently Browsing   0 members

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