Jump to content

Recommended Posts

I believe that to run a prefab file it is referenced in the modmain.lua like so

PrefabFiles = {	"charlie",}

So how to you get other files in other folders to automatically load say a custom component file?

 

On a somewhat related note:

 

I know how to call a component file, take sanity as an example.

 

inst.component.sanity.<variable>

 

Or

 

inst.component.sanity:<function>

 

How do you call a non component file directly?

 

Link to comment
https://forums.kleientertainment.com/forums/topic/28823-two-related-mod-questions/
Share on other sites

Any other file like widgets, brains, stategraphs, maps... is loaded when needed. You can see examples all over the code and you don't have to do anything different. Pretend they weren't modfiles.

Same goes for accessing them. You do it like the vanilla files do, i.e. inst.sg to get the stategraph.

Edited by Malacath

If you're adding a component like hunger - e.g. a property of something, just use "AddComponent" the same as any of Klie's components. it'll look in the component directory (yours, then the games') folders for a matching .lua file.

 

If you want to add something to the world - like "hounded" or "basehassler" (deerclops) - add them to the prefab "forest". Since this will already be defined, just use a postinit function to add more to the entity (this also works for anything already define, like pigmen or perds)

function forestpostinit(inst)	inst:AddComponent("my_new_component")endAddPrefabPostInit("forest", forestpostinit)

As for how to call non-component files directly... you generally don't. AddComponent grabs from the component directory. SetStategraph looks in the stategraphs directory for the name provided.

The two exceptions I've seen are brains and behaviors. Both of these use "require" and they seem rooted at your mod's folder. You can likely load utility files that way if your stuff doesn't fall into one of the pre-supported types.

If you're adding a component like hunger - e.g. a property of something, just use "AddComponent" the same as any of Klie's components. it'll look in the component directory (yours, then the games') folders for a matching .lua file.

 

If you want to add something to the world - like "hounded" or "basehassler" (deerclops) - add them to the prefab "forest". Since this will already be defined, just use a postinit function to add more to the entity (this also works for anything already define, like pigmen or perds)

function forestpostinit(inst)	inst:AddComponent("my_new_component")endAddPrefabPostInit("forest", forestpostinit)

As for how to call non-component files directly... you generally don't. AddComponent grabs from the component directory. SetStategraph looks in the stategraphs directory for the name provided.

The two exceptions I've seen are brains and behaviors. Both of these use "require" and they seem rooted at your mod's folder. You can likely load utility files that way if your stuff doesn't fall into one of the pre-supported types.

Thank you so much, "AddComponent" is what I was looking for.  

 

While I really do love this game and modding it,  some of the features of modding this game are very opaque. I'm glad people are willing to help. Thank you to Malacath as well for trying to help.

 

:)

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