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.

Cunning fox

Saving/loading problems.

Recommended Posts

Cunning fox    77

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


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

And my prefab post inits:

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

My whole mod is here:

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
Cunning fox    77
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:

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    351
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