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.

makar5000

Saving/loading problems.

Recommended Posts

makar5000    51

Hi everyone! I'm trying to make a mod, that adds clans in game. For now everything works just nicely, except saving and loading. 

onLoad is here:

if data~= nil then
inst.clan_image = data.clanimage
inst.clan_name = data.clan_name
end

onSave:

data.clan_image = inst.clan_image
data.clan_name = inst.clan_name

And my prefab post inits:

AddPlayersPostInit(function(inst) 
	if not inst.clanicon then
		inst.clanicon = SpawnPrefab("clanicon")
	end
	if inst.clanicon then
	--Обновляем картинку. Если не в клане, то сбросим до 0
		inst.clan_image = inst.clan_image or 0
		inst:AddChild(inst.clanicon)
		inst.clanicon.AnimState:PushAnimation("clan_"..inst.clan_image, true)
	end
	
	inst.clan_members_count = inst.clan_members_count or 0
	
	inst.OnSave = OnSave
	inst.OnLoad = OnLoad
	
end)

My whole mod is here:

clanicons.zip

I've added some prints, and found that in OnLoad everything works fine, but in PrefabPostInit everything is nil... 

Thanks everyone for your replies!

Share this post


Link to post
Share on other sites
Serpens    318

Maybe better use a component for this?
I have no knowledge about Save/Load in modmain, cause I think this is not a good way.
I would make a component that you add to every player instead.

But I know the chests mod has onsave/onload in his modmain, so maybe there is something whcih can help:
http://steamcommunity.com/sharedfiles/filedetails/?id=900083470

Share this post


Link to post
Share on other sites
makar5000    51
5 hours ago, Serpens said:

Maybe better use a component for this?
I have no knowledge about Save/Load in modmain, cause I think this is not a good way.
I would make a component that you add to every player instead.

But I know the chests mod has onsave/onload in his modmain, so maybe there is something whcih can help:
http://steamcommunity.com/sharedfiles/filedetails/?id=900083470

He did everything like I did.

I have no knowledge in making components. :D 

It's going to be much harder, than I expected:( 

Share this post


Link to post
Share on other sites
Serpens    318
5 minutes ago, makar5000 said:

He did everything like I did.

not exactly.

You see that he sets
inst.TimeToConvert = 10
in his AddPrefabPostInit function.
This would make no sense, if this value was already loaded.

So the solution is:
The AddPrefabPostInit is called BEFORE OnLoad is called.
Therefore you cant use the variables there. Instead you should use a function that is called after OnLoad.
For example
inst:DoTaskInTime(0.01,function(inst) ...end)

Share this post


Link to post
Share on other sites