Jump to content

41.71: SandboxVars seems broken on reload of single player game


Xyberviri

Recommended Posts

I created a mod that adds some items to the loot table, I decided to add some sandbox-options for the player enable the setting if they dont want parts of it going out. I noticed im only able to read sandboxvars on the creation of a single player game the first time its created. On following reloads the sandboxvars are not avalible until after i load in the game which causes lua code to bomb out if where messing with the loot table.
 

option CarWanna.EnablePinkSlipLoot = {
    type = boolean,
    default = false,
    page = CarWanna,
    translation = CarWanna_EnablePinkSlipLoot,
}

 

then in media\lua\server\items\whatever.lua

 

print("CarWanna Loot Enabled".. tostring(SandboxVars.CarWanna.EnablePinkSlipLoot))

 

this will report true the firs time i start a new game, but every time after that i see false in the console.txt.

 

but if i start the game in debug mod and type the following in my lua console:

print( SandboxVars.CarWanna.EnablePinkSlipLoot )

I will see variable as true, this seems like a bug because the issue occurs on reloads of the same save file, but not on initial creation. 

 

I tried sticking this in Events.OnGameStart but im guessing maybe i need to wait for a later event as a work around. its 2:39am and i wanted to type this up before trouble shooting event orders, so ill test that in the morning.

 

edit: tried OnPreDistributionMerge ,OnLoad,OnServerStarted,OnPostMapLoad, all of them seem to no see the sandbox variables except on first boot....

 

I can read it with the lua console when i join so i know at some point its loaded, I just cant read it with scripts.  I also tried getSandboxOptions and that isnt loading the current config during those events.

Edited by Xyberviri
Link to comment
Share on other sites

"edit: tried OnPreDistributionMerge ,OnLoad,OnServerStarted,OnPostMapLoad, all of them seem to no see the sandbox variables except on first boot...."

 

You need to do after OnInitWorld, like this 

 

Events.OnInitGlobalModData.Add(function() print(myvar) end)

Link to comment
Share on other sites

Ah no, that doesnt appear to be working either, i also tried OnReceiveGlobalModData, OnGameTimeLoaded & OnLoginStateSuccess

local function TestVars(location,event)
print("SandBox Variable "..location.." "..event.." Test boolean value: ".. tostring(SandboxVars.SandTest.isTrue))
print("SandBox Variable "..location.." "..event.." Test boolean value: ".. tostring(getSandboxOptions():getOptionByName("SandTest.isTrue"):getValue()))    
end

Events.OnGameStart.Add(TestVars("server","OnGameStart"))
Events.OnLoad.Add(TestVars("server","OnLoad"))
Events.OnServerStarted.Add(TestVars("server","OnServerStarted"))
Events.OnPostMapLoad.Add(TestVars("server","OnPostMapLoad"))
Events.OnInitGlobalModData.Add(TestVars("server","OnInitGlobalModData")) 
Events.OnReceiveGlobalModData.Add(TestVars("server","OnReceiveGlobalModData")) 
Events.OnGameTimeLoaded.Add(TestVars("server","OnGameTimeLoaded"))
Events.OnLoginStateSuccess.Add(TestVars("server","OnLoginStateSuccess"))

I also have a copy of this in server and shared.... sandbox options seem broke... i guess if there is a way to read the ini files directly i can try sneaking back up one up and over via lua and see if that works. but at this point its easier to use mod options.

 

This is all in single player and local hosts ive tested, ive even uploaded it to a test server and i get the same results. sandbox options are broken until some event i havent found yet. they work once i join the game and try to test it with debug console but i cant figure out how to use them with mods on launch of a server yet.

Edited by Xyberviri
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...