Jump to content

Overriding Default Prefab issues


XainFaith

Recommended Posts

Hello there first off would like to say that don't starve has got to be one of my all time favorite games i absolutely love survival games and this one both in game play and artistic style floats my boat quite well.

 

A bit about my own background i have been programming all kinds of things for a very long time now 12+ years easily everything from c to php and in between ... except VB... 

 

now on to the problem i am having.

 

I was under the impression that simply including a script with the same name would override the core assets version of that script in testing this does and does not seem to be the case.

 

For example custom code for the brain of the rabbit i am modding does seem to get hit but trying to add a component to the rabbits init function seems to fail so where that component is being relied on in the brain it of course fails and throws an exception of an invalid index.

 

i have placed a print function in the rabbits init function but i do not see it in the console output at all nor does the debug statement make it into the log ether.

 

so ether my assumptions of how i can override the core script for the rabbit is incorrect or i am missing something and i am just not sure what that might be.

 

Any ideas would be greatly appreciated.

 

Regards XainFaith

Link to comment
Share on other sites

Overriding files should be a last resort. See: http://forums.kleientertainment.com/index.php?/files/file/203-api-examples/

If you only want to add a component to a prefab, use:

AddPrefabPostInit( "prefabname", function(inst)    inst:AddComponent( "componentname" )end )
in your modmain.lua

If you really need to override a file, you create the same directory structure in your mod folder as the data/scripts folder. For example, scripts/prefabs/rabbit.lua would be potentially overwritten by mods/<modname>/scripts/prefabs/rabbit.lua. However, I'm not sure about the specifics of what files can be overwritten because it really should be the very, very last resort.

Link to comment
Share on other sites

Thank you for the quick response i looked at the api example and no longer have to override the rabbit prefab however it seems that i still require to do so for the rabbit brain it seems, although i may be able to restructure the behavior tree but this in the end would have the same effect regardless.

 

Regards XainFaith

Link to comment
Share on other sites

Thank you for the quick response i looked at the api example and no longer have to override the rabbit prefab however it seems that i still require to do so for the rabbit brain it seems, although i may be able to restructure the behavior tree but this in the end would have the same effect regardless.

 

Regards XainFaith

You could use one of the class post construct functions to hook into the RabbitBrain I believe, or, because the rabbitbrain.lua returns the RabbitBrain class, you can use require to get the class from the file and then alter it.

Example:

-- if in modmain.lua, this is neededlocal require = GLOBAL.requirelocal RabbitBrain = require "brains.rabbitbrain"-- if you want to extend rather than overwrite, then save the original function firstlocal RabbitBrain_OnStart_base = RabbitBrain.OnStart or function() endfunction RabbitBrain:OnStart()    -- if you are extending rather then overwriting, then call the original function    -- self is an implied parameter in obj:func() notation so we need to send it specifically here    -- for example, RabbitBrain:OnStart() is the same as RabbitBrain.OnStart( self )    RabbitBrain_OnStart_base( self )        -- your codeend
If you can do it this way, then it would be ideal because it means it's much more likely that your code will be compatible with other mods (if you overwrite a file, then other mods could easily step on your code). In looking at the brain code, it'll definitely be harder to extend rather than just overwrite. In my opinion, it'd still be better to use the require method above and then just overwrite only the functions that you need to (probably OnStart I'm guessing).
Link to comment
Share on other sites

Sorry for the late reply. But that kind of a solution should do quite nicely actually since any custom code is only dependent on the particular character you play this will keep things a lot cleaner. Lua has some well what i can only see as odd ways of doing things .. i do not use a scripting language very often if at all mostly languages that need to be compiled.

 

Anyways thanks again with this i should be able to head forward quite nicely.

Link to comment
Share on other sites

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.

×
  • Create New...