Jump to content

[(should be)Fairly Simple]Function to return string name of headgear?


Somnei

Recommended Posts

Interesting.

 

Where did you put the debug part when it correctly printed "head: Top Hat"? Was it right before this line (inside the custom_desc function)?

 

 

local function custom_desc(inst)    local desc = inst.name .. ", " .. "Basic desc." --debuggingfor k, v in pairs(inst.components.inventory.equipslots) do    if v ~= nil then v_name = v.name end    print(k .. ": " .. v_name)end           if inst.components.inventory.equipslots then    local headgear = inst.components.inventory:GetEquippedItem(inst, GLOBAL.EQUIPSLOTS.HEAD)       end    if headgear ~= nil then        desc = inst.name .. ", " .. desc .. " " .. headgear.name     end    return descend
Yeah, it was o;
Link to comment
Share on other sites

@SophieTheDog, change this:

if inst.components.inventory.equipslots then

to this:

if inst.components.inventory.equipslots ~= nil then

Edit:

I tried running the mod with only one other mod (no warnings mod), and it still doesn't work. All the UI elements are disabled when I load the world, and any sort of input is impossible.

I'd try testing these small changes myself, but that won't be happening unless I can get it to work for me at all.

 

If the debug code was able to find the correct element, then it shouldn't be any different for the other one. I suspect that "inst.components.inventory.equipslots" is considered a false value (it's actually a table) when tested by the "if" statement, so it doesn't allow the rest of the code to execute.

Checking if it's nil instead may work, though.

 

Link to comment
Share on other sites

@SophieTheDog

 

._. So apparently the problem was just with the scope of "headgear"

 

Fixed code, tested, works:

local function custom_desc(inst)	local desc = inst.name .. ", " .. "Basic desc."--	for k, v in pairs(inst.components.inventory.equipslots) do--		local v_name--		if v ~= nil then v_name = v.name end--		print(k .. ": " .. v_name)--	end		local headgear		if inst.components.inventory.equipslots ~= nil then		headgear = inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HEAD)	end	if headgear ~= nil then		desc = inst.name .. ", " .. desc .. " " .. headgear.name	end	return descend

Though I'm curious why the hat is set to hidden.

 

 

Link to comment
Share on other sites

@SophieTheDog

 

._. So apparently the problem was just with the scope of "headgear"

 

Fixed code, tested, works:

local function custom_desc(inst)	local desc = inst.name .. ", " .. "Basic desc."--	for k, v in pairs(inst.components.inventory.equipslots) do--		local v_name--		if v ~= nil then v_name = v.name end--		print(k .. ": " .. v_name)--	end		local headgear		if inst.components.inventory.equipslots ~= nil then		headgear = inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HEAD)	end	if headgear ~= nil then		desc = inst.name .. ", " .. desc .. " " .. headgear.name	end	return descend
Though I'm curious why the hat is set to hidden.

wow, that's a stupid error haha </3

oh well, I'm really grateful! Thank you so so so much Blueberrys <3

also, hat is hidden because it doesn't exist anyways. This is the way it's coded inside the pig prefab, and I'm considering trying to make it possible to see the hat (by making an "animation" for it - just not really sure how to do that haha)

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