Jump to content

Recommended Posts

Hey all. Taking my first steps into making an Actual Mod that's not a simple tweak and I think I'm missing something super obvious, and it's infuriating.

 

I'm trying to modify pigman behavior if they're wearing a miner's helmet:

 

(this is in brains\pigbrain.lua)

 local function HasLightHat(inst)        local thehat = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)        return thehat and thehat.prefab == "minerhat" end
 
So far so good. We return true if the pig is wearing a miner's helmet.
Now when I'm trying to check whether it's on or not:
 
local function GetLightHatState(inst)        local thehat = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)        return HasLightHat(inst)-- and thehat.components.machine:IsOn()end
(obviously suboptimal)
 
For some reason thehat doesn't seem to contain any components, even though the prefab script says that it should have 'fueled' and 'machine' at least. The game's stock scripts seem to reference components in this fashion. Am I missing a level of indirection here or is there something weird going on? 
 
Also, is there a simple way to dump a table's contents to the console? dumptable() seems to cause a crash.

The minerhat does not have a machine component. It turns off when unequipped or after running out of fuel.

Maybe you are thinking of the mininglantern?

 

Check for

thehat.components.fueled.consuming

as it will be true when on, and false when off.

 

Also, dumptable works like this,

local t = {	hello = {"world", "yes"},	"oat",	kablam = 9}print(GLOBAL.dumptable(t))-- print(dumptable(t)) outside modmain.lua

Yup, it was the mining lantern. I didn't realize all the hats were lumped together in one file. I knew it was something simple like that. Everything's working now, thanks!

 

I had tried calling dumptable like that (on thehat.components) but it just hung DST. No idea what happened there.

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