Jump to content

Recommended Posts

hi,

is there a way to check an item's tab from the item object ? something like

if item.recipe.tab == "light" then do something end.

reason I ask this, is because I'm trying to find objects in the player inventory that belong to a category. For objects that provide light

item["Light"]

returns True for lanterns & light giving objects such as some amulets, however for torches & molehat the only thing I could find to check is them directly (e.g. item.prefab == "torch" or "molehat"). This is less than ideal in my opinion though, since I'd like for my mod to be compatible with everything right off the bat & not have conditions of hell that check for 999 different items from mods or expansions.

 

Thanks. any answer welcome.

You can check the global recipes. Here's some pseudo-code.

GetAllRecipes()["prefabname"].tab == "tabname"

Needless to say, you have to replace "prefabname" with the name of the prefab (also accessible using item.prefab, as you stated correctly) and tabname with the code name of the tab.

You probably want to check if the recipe even exists though:

if GetAllRecipes()
and GetAllRecipes()[inst.prefab].tab == "WAR" then

so... the check wasn't working so I implemented a print

Spoiler

 


local recipes = GLOBAL.GetAllRecipes()
for ...
            print(item.prefab)
            if recipes[item.prefab] then
                print(recipes[item.prefab].tab)
            end
    ...
end

 

had to use GLOBAL, otherwise the game was crashing complaining about indexing a nil value (GetAllRecipes)
this returns :

Spoiler

 


../mods/SortInventory Altered/modmain.lua(362,1) book_sleep	
../mods/SortInventory Altered/modmain.lua(364,1) table: 111BF578	
../mods/SortInventory Altered/modmain.lua(362,1) book_brimstone	
../mods/SortInventory Altered/modmain.lua(364,1) table: 111BF578	
../mods/SortInventory Altered/modmain.lua(362,1) strawhat	
../mods/SortInventory Altered/modmain.lua(364,1) table: 14380E08	
../mods/SortInventory Altered/modmain.lua(362,1) molehat	
../mods/SortInventory Altered/modmain.lua(364,1) table: 14380D90	
../mods/SortInventory Altered/modmain.lua(362,1) honey	
../mods/SortInventory Altered/modmain.lua(362,1) seeds	
../mods/SortInventory Altered/modmain.lua(362,1) stinger

 

so obviously it wasn't returning a value but a table instead. So I looked through files & came up with this :

local RECIPETABS = GLOBAL.RECIPETABS
...
if (recipes[item.prefab].tab == RECIPETABS.LIGHT) then ...

which works finally. Thanks a lot :)

Edited by whismerhill

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