Jump to content

Recommended Posts

How to add mod Asset in Vanilla Prefabs? I doing like this but is not working....
 
AddPrefabPostInit("portablespicer", function(inst)

    table.insert(GLOBAL.Prefabs['portablespicer'].assets,Asset("ANIM", "anim/water_spice.zip"))
    table.insert(GLOBAL.Prefabs['portablespicer'].assets,Asset("ANIM", "anim/water_plate_food.zip"))

    if not GLOBAL.TheWorld.ismastersim then
        return inst
    end

    if inst.components.stewer ~= nil then
        if inst.components.stewer.ondonecooking ~= nil and inst.components.stewer.ondonecooking_old == nil then
            inst.components.stewer.ondonecooking_old = inst.components.stewer.ondonecooking
        end
        inst:DoTaskInTime(0, function()    
            inst.components.stewer.ondonecooking = changeanim
        end)
    end
end)

Where did I go wrong?

 
3 hours ago, Leonidas IV said:

Well, that doesn't work. The Assets table in the prefab is simply to load them into the game, and they don't exactly need to be inside the prefab. You can simply add these assets to the Assets table in modmain.

I'll give it a try.

 

3 hours ago, Leonidas IV said:

Well, that doesn't work. The Assets table in the prefab is simply to load them into the game, and they don't exactly need to be inside the prefab. You can simply add these assets to the Assets table in modmain.

Well, if I don't understand it well, I'll write modmain like

table.insert(GLOBAL.Prefabs['portablespicer'].assets,Asset("ANIM", "anim/water_spice.zip"))
table.insert(GLOBAL.Prefabs['portablespicer'].assets,Asset("ANIM", "anim/water_plate_food.zip"))

but i got like bug

[00:00:03]: [string "../mods/water_mod/scripts/water_main.lua"]:485: attempt to index field 'portablespicer' (a nil value)
LUA ERROR stack traceback:
        ../mods/water_mod/scripts/water_main.lua(485,1) in function 'result'
        scripts/mods.lua(330,1) in function 'modimport'
        ../mods/water_mod/modmain.lua(34,1) in main chunk
        =[C] in function 'xpcall'
        scripts/util.lua(780,1) in function 'RunInEnvironment'
        scripts/mods.lua(563,1) in function 'InitializeModMain'
        scripts/mods.lua(537,1) in function 'LoadMods'
        scripts/main.lua(356,1) in function 'ModSafeStartup'
        scripts/main.lua(477,1) in function 'callback'
        scripts/modindex.lua(103,1) in function 'BeginStartupSequence'
        scripts/main.lua(476,1) in function 'callback'
        scripts/modindex.lua(735,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(709,1) in function 'Load'
        scripts/main.lua(475,1) in main chunk
[00:00:03]: [string "scripts/mainfunctions.lua"]:1485: variable 'global_error_widget' is not declared
LUA ERROR stack traceback:
        =[C] in function 'error'
        scripts/strict.lua(23,1)
        scripts/mainfunctions.lua(1485,1)
        =[C] in function 'GetPersistentString'
        scripts/quagmire_recipebook.lua(54,1) in function 'Load'
        scripts/main.lua(374,1) in function 'ModSafeStartup'
        scripts/main.lua(477,1) in function 'callback'
        scripts/modindex.lua(103,1) in function 'BeginStartupSequence'
        scripts/main.lua(476,1) in function 'callback'
        scripts/modindex.lua(735,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(709,1) in function 'Load'
        scripts/main.lua(475,1) in main chunk

If it is wrong, how should I write it?

The mod enviroment looks for assets to load in the variable "Assets" (a table), so you just need to re-create it or insert your assets in it:

Assets = {
    Asset("ANIM","anim/water_spice.zip"),
    Asset("ANIM", "anim/water_plate_food.zip"),
}

 

 

  • Like 2

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
×
  • Create New...