Identifying Items or Entities Lacking elem_tooltip

Place to get help with not working mods / modding interface.
Sheridan
Inserter
Inserter
Posts: 31
Joined: Wed Dec 13, 2017 5:27 pm
Contact:

Identifying Items or Entities Lacking elem_tooltip

Post by Sheridan »

Hello everyone,

I am currently working on a script to identify items or entities that cannot have their own elem_tooltip. I have implemented the following code:

Code: Select all

local function filter_unknown_prototype_name(prototype_name)
  if prototype_name == "elevated-straight-rail"
  or prototype_name == "straight-rail"
  or prototype_name == "elevated-curved-rail-a"
  or prototype_name == "elevated-curved-rail-b"
  or prototype_name == "curved-rail-a"
  or prototype_name == "curved-rail-b"
  or prototype_name == "elevated-half-diagonal-rail"
  or prototype_name == "half-diagonal-rail"
  then return "rail" end
  return prototype_name
end
...
gui.add{
...
  elem_tooltip =  {
                            type    = 'item-with-quality',
                            name    = filter_unknown_prototype_name(prototype.name),
                            quality = quality.name,
                          }
}
So far, this hardcoded solution works, but I am looking for advice on making this function more generic. Ideally, I would like the method to handle entities added by other mods without needing to update the code each time.

Does anyone have suggestions on how to achieve this? Any guidance or tips would be greatly appreciated!

Thank you in advance for your help.
Please consider English is not my native language.
s6x
Inserter
Inserter
Posts: 41
Joined: Fri Nov 15, 2024 8:22 pm
Contact:

Re: Identifying Items or Entities Lacking elem_tooltip

Post by s6x »

One thing that would help your solution be more generic is that you probably want to use a dictionary rather than a big if statement. This won't specifically make anything more automatic but it will make your code a whole lot more extensible. If you're feeling ambitious you could even set it up to allow other mods to add to the table.

Code: Select all

local prototype_table = {
   ["elevated-straight-rail"] = "rail",
   -- etc..
}
local function filter_unknown_prototype_name(prototype_name)
   if prototype_table[prototype_name] then
      return prototype_table[prototype_name]
   else
      return prototype_name
   end
end
Post Reply

Return to “Modding help”