Jump to content

Modding Questions that an Absolute Novice Would Have

Recommended Posts

So I'm trying to make a custom character based on the ancient fuelweavers right? I have searched for a long while and I'm still haunted by something that I see in the code constantly.


As silly as it might sound, I am at my wits end because I have no clue what this "inst" variable is. I have gone through countless guides, ones on this forum, and ones elsewhere, and no where do I find anything that talks about it. Once again:


local function DontTriggerCreep(inst)


What does that inst mean?!

I am trying my best to figure this out, but its high time I come to ask on this forum, maybe someone better at this would know.


Link to comment
Share on other sites

This is the wrong section but I can clarify this for you.  Now, I’ve been modding for some years now and am a little over a year from finishing a bachelor’s in computer science, so I apologize if my answer is incomplete.


Lets look at two usages of inst.




inst in this case refers to the prefab we’re in.  Inst is one of the ways to refer to a prefab.

With that code we’re checking within a prefab, among their components (if any) for the health component.  If it exists, we use the SetMaxHealth method within the health component to set the max health value for that prefab.

That syntax is referred to as dereferencing.  Each period represents going “into” an object and looking for something the same way you’d open a box and search for something.  In this analogy, components exist “inside” the prefab inst refers to.  If the box does not exist, then the program will crash because you can’t open and search a non-existent box.

In lua, one way to solve these sorts of issues is if it is possible for inst to not exist (lua can compare to nil for things that don’t exist) to handle that sort of code.

when you see code with inst and add component, it’s adding a component to a prefab.  That means you can do method calls that use that component like health has setmaxhealth.

The other common way to see inst used is as an argument, which is a parameter passed into a method such as in:

local function DontTriggerCreep(inst)

In this case the inst passed in refers to a prefab, which the method will act upon.  Usually if the inst is nil or in shorthand, does not exist, you’ll get a crash because the method will almost certainly be dereferencing it.

Again, I’m still very much a novice at lua and while I’ve played around with the code for don’t starve a lot I still don’t have a deep understanding of how it all works syntactically.

Best of luck!

Link to comment
Share on other sites


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