Hello,
I am trying to migrate a Mod logic to server side to avoid to have several clients doing the same, and to avoid to have clients with old data or new clients with no data it all.
My problem is that I am not able to keep the data upon server restarts, and doing tests I have seen that while the SP mode saves the ModData in a table that is visible on debug mode and preserved forever, the MP mode keeps that table only when the server is running and is deleted once is restarted.
I have tried the save world command to see if maybe it requires a manual save, but same behaviour.
I am using this simple lua test script:
-- Testing!
if isClient() then return end
if ModData.exists("ISA_TEST") == false then
print("ISA: No Data... creating new data.")
local data = ModData.getOrCreate("ISA_TEST")
data.test = "Testing the ModData"
else
print("ISA: Data Found!!! Finally is working!!")
local data = ModData.get("ISA_TEST")
print("ISA: " .. data.test)
end
if ModData.exists("ISA_TEST") == true then
local test = ModData.get("ISA_TEST")
print("ISA: Type - " .. type(test))
print("ISA: Test Data - " .. ModData.get("ISA_TEST").test)
end
The first "if" always gives false because there is no data on boot. Then the data is created and the second "if" gives true because the data exists.
LOG : General , 1648370405885> 2,530,238> ISA: No Data... creating new data.
LOG : General , 1648370405886> 2,530,239> ISA: Type - table
LOG : General , 1648370405886> 2,530,239> ISA: Test Data - Testing the ModData
I have seen that the 41.68 changelog includes this:
Fixed GlobalModData.save() not being called on the server.
But even with that. the data is not preserved.
Maybe I'm doing something wrong, but there is no data about this topic nowhere so I am just doing a "testing & error" method.
Version: 41.68, but also tested on 41.65 with same problem.
Multiplayer
Hosted on Docker container using linux. I am sure that is not a "volatile" storage problem, because all the server data is preserved and only the ModData is removed.
Mods: Just the mod I am testing
Reproduction steps:
Create a Mod with the above code to run it in server
Run the server to start the script
Optional because it still failing: Enter into the server as admin and run the /save command
Stop the server to restart it
Start the server again and see how the data is not there
Best regards