Jump to content

Stack Traceback on GetSaveRecord() with modded companion

Recommended Posts

So one of my users has the following error



It occur's presumably when a user's disconnects and triggers the OnSave which saves the companion.


Due to the user's large amount of mod's I'm having them get me a list so I can determine whether the source is my mod, but in the meantime.


here is my code

local function OnSave(inst, data)    if inst.taifriend ~= nil then        data.taifriend = inst.taifriend:GetSaveRecord()    endend

Compared to Wendy's code (Where it was based on)

local function OnSave(inst, data)    if inst.abigail ~= nil then        data.abigail = inst.abigail:GetSaveRecord()    endend

The companion is getting saved in the same exact way that Abigail get's saved.  The despawn code for the companion is the same too.


Here's the portion of entityscript.lua that SHOULD be giving the error (assuming the user doesn't have entityscript modded)

    if self.Transform then        local x, y, z = self.Transform:GetWorldPosition()                --Qnan hunting        x = x ~= x and 0 or x        y = y ~= y and 0 or y        z = z ~= z and 0 or z        record.x = x and math.floor(x*1000)/1000 or 0        record.z = z and math.floor(z*1000)/1000 or 0        --y is often 0 in our game, so be selective.        if y ~= 0 then            record.y = y and math.floor(y*1000)/1000 or 0        end    end 

From what I can read in the error, it looks like entityscript.lua is getting x as a nil value when it should be getting the x coordinate from self.Transform:GetWorldPosition()



My question though, assuming entityscript wasn't modded to cause this issue.  Is there something my mod might have done to cause the GetSaveRecord() to get screwed up?  I haven't adjusted entityscript with my mod for the record.


Edit: Thinking about it now, wouldn't overriting a file cause it to show up in the stack traceback?


I'm still trying to figure out why this error would happen.  Best I can assess is that GetWorldPosition is returning nil values, but if inst was nil, wouldn't that have been caught in my logic gate here?

local function OnSave(inst, data)    if inst.taifriend ~= nil then        data.taifriend = inst.taifriend:GetSaveRecord()    endend

Edit 2: Found the cause, the error happens when the server saves while the companion is dead.  Strange though that it happens, but now that I know the cause I can fix it.


I'm guessing the reason my logic gate didn't work here is because even though the companion was dead, inst.taifriend wasn't nil.  All I had to do was add inst.taifriend.components.health and inst.taifriend.components.health:IsDead() ~= true and it was fixed.  


Why doesn't abigail have this issue?

Edited by Zackreaver
Link to comment
Share on other sites

If you put this is your modmain and run it in the game:

print("Here we go")local abi = GLOBAL.SpawnPrefab("abigail")local inter = abiabi:Remove()print(inter)print("Here we stop")

You will get:

[00:00:22]: Here we go	[00:00:22]: 116101 - abigail	[00:00:22]: Here we stop

We removed abi, but inter is not nil.


You are trying to save an entity that was removed, thus, it still "exists", but with no world position, according to our little test.


The crux of the matter is this line you commented in the Tai prefab:

player:ListenForEvent("onremove", unlink, inst)

that would contain:

local function unlink(inst)    inst._playerlink.abigail = nil    --- other codeend

which is in abigail's code, and not yours.


The solution to keep OnSave as it is on Wendy's code, would be to uncomment that line, and put:

local function unlink(inst)    inst._playerlink.taifriend = nilend

in Tai.lua. This way, inst.taifriend in Charlie.lua will be nil if you are saving the game and Tai is dead.


So, in short:



Why doesn't abigail have this issue?

Because you didn't copy all the code.

Edited by DarkXero
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...