How to access the localised_name of an unknown entity?
Posted: Thu Sep 05, 2019 7:50 pm
I've looked at the localization tutorial and elsewhere, but I can't quite figure out how to access the localized name of an unknown entity. This example
There are different entities of the type "car" -- even in vanilla, you have the car and the tank, and mod authors may use the car prototype to disguise whatever they want as a car. So, if you don't know what mods may be installed and what entity names they might use, you can't really use constants. There must be some simple way to get it right, but I really don't see it. Can anybody help me out, please? 
Yes, I know the example is about an item, not an entity, but the category shouldn't matter here.
from the wiki seems easy enough:but that is because you know you're looking for iron-plates and can use a constant in your code. But how about the following?game.print({"item-name.iron-plate"})
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
local entity = event.created_entity
local vehicles = entity.surface.find_entities_filtered{area = area.create(entity.position,1), type = "car"}
for i in pairs(vehicles) do
local found_vehicle = vehicles[i]
game.print("Your vehicle is a " .. {found_vehicle.localised_name})
end
end
