Jump to content

Mod help: Component OnLoad function not running.


Recommended Posts

I have been trying to update my Stat shuffle mod and I wanted to add a mode where the "shuffle" that the player gets is linked to the world rather than the individual player, that way every player can get the same shuffle. But this had come with a few issues, the only way I know how to save data of the world is through a component but after making it into a component the OnLoad function never runs at all. I have prints as the first line in both the OnSave and OnLoad functions, the OnSave works perfectly as expected but the OnLoad appears to be completely ignored never printing anything to the console and never loading the save data at all. I thought maybe the save data is becoming invalid some how, but  I can't spot any differences between my functions and those of components in the game that I know do work. I asked around some modding communities for help and they couldn't spot anything amiss either. Eventually we all came to the conclusion that my game is cursed.

I have the component "WorldShuffle.lua" below so you all can take a look and let me know if I missed something and the "modmain.lua" just in case that helps somehow with anyone's investigation.

worldshuffle.lua modmain.lua

Link to comment
Share on other sites

8 hours ago, Rickzzs said:

With my knowledge I never thought AddPrefabPostInit can affect onload function. The prefab is already loaded. Perhaps loadpostpass? I guess you see how game load savedata to decide. I suggest you save it into the component.

I am trying to save it in a component, the OnLoad function of the component on the world is not running at all. Sidenote: I am changing the OnLoad and OnSave of the player using the AddPrefabPostInit and that part is working just fine, but because the world does not have OnLoad and OnSave functions I needed to use a component, which as I mentioned, is not running the OnLoad function at all but is running the OnSave function just fine.

Link to comment
Share on other sites

2 hours ago, poolcool2 said:

I am trying to save it in a component, the OnLoad function of the component on the world is not running at all. Sidenote: I am changing the OnLoad and OnSave of the player using the AddPrefabPostInit and that part is working just fine, but because the world does not have OnLoad and OnSave functions I needed to use a component, which as I mentioned, is not running the OnLoad function at all but is running the OnSave function just fine.

In this case I suggest you trace the whole thing by overwriting the prefab, inserting prints into gamelogic or some 'spawnsaverecord' functions I can't recall. I guess the world is a special prefab.

Edited by Rickzzs
Link to comment
Share on other sites

8 hours ago, Rickzzs said:

In this case I suggest you trace the whole thing by overwriting the prefab, inserting prints into gamelogic or some 'spawnsaverecord' functions I can't recall. I guess the world is a special prefab.

I don't even know where I would begin with that, I don't know anything about how objects are loaded outside of the OnSave and OnLoad functions being part of it and much less about how the world prefab or it's components are saved and loaded.

Link to comment
Share on other sites

6 hours ago, poolcool2 said:

I don't even know where I would begin with that, I don't know anything about how objects are loaded outside of the OnSave and OnLoad functions being part of it and much less about how the world prefab or it's components are saved and loaded.

I cannot help you further if you don't try to learn them. I looked at the code a bit and find gamelogic.PopulateWorld and entityscript.SetPersistData are the functions that load data from save file. Check your save file, insert prints into lua files and override them(you must know the override method), see log file and witness what happened.

Link to comment
Share on other sites

3 hours ago, Rickzzs said:

I cannot help you further if you don't try to learn them. I looked at the code a bit and find gamelogic.PopulateWorld and entityscript.SetPersistData are the functions that load data from save file. Check your save file, insert prints into lua files and override them(you must know the override method), see log file and witness what happened.

I had already previously taken a look at entityscript.SetPersistData before and it didn't seem to have anything about the world itself or it's components but gamelogic.PopulateWorld is something I have not seen before and it looks like it might be able to help. I'll take a closer look when I have time and get back to you on if I have found a solution or not.

Link to comment
Share on other sites

15 hours ago, Rickzzs said:

I cannot help you further if you don't try to learn them. I looked at the code a bit and find gamelogic.PopulateWorld and entityscript.SetPersistData are the functions that load data from save file. Check your save file, insert prints into lua files and override them(you must know the override method), see log file and witness what happened.

Sadly I couldn't find what I was looking for in gamelogic.PopulateWorld or anything else in gamelogic for that matter.

Link to comment
Share on other sites

Hate to revive an old thread, but I ran into this issue today. From what I was able to tell, if your component's OnSave doesn't return a table with SOMETHING in it, OnLoad will not fire at all, ever. For my use case I didn't need to save any real data, I just needed OnLoad to fire a sequence at a specific time, so I wrote my OnSave like this.

function Badge:OnSave()
    return { stuff = true }
end

Hope this helps anyone who runs into this issue.

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
 Share

×
  • Create New...