Jump to content

Inventory item name versus prefab name?


Recommended Posts

I've been debugging my cooking logic for a time now, and finally found a reason that my calls are returning trash. I need to get ingredients from a container, scan them for tags and add all of them. Problem is, inventory items have a different naming convention compared to prefabs, so I can't seem to figure out how to mix them.

To give a concrete example, I spawn a potato via c_spawn("potato"). I put it into the container, then scan its name. As it came from an inventory, its name variable contains "Potato" with a upper-case P, which does not get registered as the same thing. Formatting can get even worse for Wet Goop ("wetgoop"), Cooked Carrot ("carrot_cooked") and Rot ("spoiled_food").

I could technically fix this by creating a huge alias table in my file, but this gets messy real quick and seems very forced, and also does not update or localize well. Is there another way to recover the prefab name from the inventory item name?

Link to comment
Share on other sites

The names you view come from STRINGS.NAMES, where they are structured as prefab = "display name".

You can do a reverse lookup with Klei's table.reverselookup(t, lookup_value) to get the prefab name capitalized. Here's an example.

local prefabUpper = table.reverselookup(GLOBAL.STRINGS.NAMES, "Rot")
--> "SPOILED_FOOD"
local prefab = prefabUpper:lower()
--> "spoiled_food" 
-- ^ is standard prefab case convention

 

Edited by penguin0616
  • Like 2
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...