Jump to content

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?

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

Wouldn't really help you avoid crashes, nor does it have a use in most cases.

http://lua-users.org/wiki/EnvironmentsTutorial#:~:text=Environments in Lua 5.1,the getfenv %2F setfenv standard functions.

Edited by penguin0616
  • Like 2

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