makar5000

Saving/loading problems.

4 posts in this topic

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
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:( 

Edited by makar5000

Share this post


Link to post
Share on other sites
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)

Edited by Serpens

Share this post


Link to post
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