Jump to content

Data Not Saving


Nycidian

Recommended Posts

From when I made other mods I was under the impression that to save and reload variables in components all one had to do was something like...

function Amanager:OnSave()	return { killed = self.killed, }endfunction Amanager:OnLoad(data)	if data.killed ~= nil then		self.killed = data.killed	endend

...but for some reason neither of these functions are firing. My guess is I'm missing something obvious but for the life of me I can't find it. Here is the mod...

 

achieve_0.1_working.zip

 

...if anyone could point out what I am doing wrong I would appreciate it.

Link to comment
Share on other sites

If you're adding the component to a character prefab using SimPostInit, saving won't work. Not totally sure the cause, but simplex posted a workaround here

Since his code got smashed into one line, here it is in the proper format:

-- need to add the component in here, otherwise OnSave doesn't work rightAddPrefabPostInit("world", function(inst)	GLOBAL.assert( GLOBAL.GetPlayer() == nil )	local player_prefab = GLOBAL.SaveGameIndex:GetSlotCharacter()	-- Unfortunately, we can't add new postinits by now. So we have to do	-- it the hard way...	GLOBAL.TheSim:LoadPrefabs( {player_prefab} )	local oldfn = GLOBAL.Prefabs[player_prefab].fn	GLOBAL.Prefabs[player_prefab].fn = function()		local inst = oldfn()		-- Add components here.		inst:AddComponent("yourcomponent")		return inst	endend)
Link to comment
Share on other sites

If you're adding the component to a character prefab using SimPostInit, saving won't work. Not totally sure the cause, but simplex posted a workaround here

Since his code got smashed into one line, here it is in the proper format:

-- need to add the component in here, otherwise OnSave doesn't work rightAddPrefabPostInit("world", function(inst)	GLOBAL.assert( GLOBAL.GetPlayer() == nil )	local player_prefab = GLOBAL.SaveGameIndex:GetSlotCharacter()	-- Unfortunately, we can't add new postinits by now. So we have to do	-- it the hard way...	GLOBAL.TheSim:LoadPrefabs( {player_prefab} )	local oldfn = GLOBAL.Prefabs[player_prefab].fn	GLOBAL.Prefabs[player_prefab].fn = function()		local inst = oldfn()		-- Add components here.		inst:AddComponent("yourcomponent")		return inst	endend)

Thank you,  that's good to know I thought I was going crazy

 

thanks @simplex as well.

Link to comment
Share on other sites

Just curious if I'm mistaken here, but from my experience they work when adding them via PrefabPostInit. I know this is problematic with mod characters but as long as you are interested in adding a component to your own mod character that should be easier than what you're doing now.

Link to comment
Share on other sites

Just curious if I'm mistaken here, but from my experience they work when adding them via PrefabPostInit. I know this is problematic with mod characters but as long as you are interested in adding a component to your own mod character that should be easier than what you're doing now.

Using AddPrefabPostInit works, what doesn't is using AddSimPostInit. So the above workaround is for when you want to add a component to all player characters, not just a predetermined subset.

Link to comment
Share on other sites

Just curious if I'm mistaken here, but from my experience they work when adding them via PrefabPostInit. I know this is problematic with mod characters but as long as you are interested in adding a component to your own mod character that should be easier than what you're doing now.

What I'm doing is making a modular mod that all you have to do is add a few lines of code to the modmain and it runs a few different lua files that add in more than just a lone component could do (at least as far as I can tell there are things in my achieve.lua that I can't do in a component file). The other thing I believe it will do is if multiple mods use these files it will only install it once, though I need to test this feature to make sure.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...