Page 1 of 1

Entities with the same name

Posted: Wed Jul 20, 2022 3:27 pm
by Pi-C
I've always wondered what would happen if there were two entities of a different type, but with the same name. Now that there's a new mod that creates a spider-vehicle prototype for a given car prototype, this isn't just a theoretical question anymore:
same_name.png
same_name.png (65.87 KiB) Viewed 1036 times
As they are defined as data.raw.car.car and data.raw["spider-vehicle"].car, they are in separate name spaces, so creating the prototypes is not a problem. But what about the control stage? For example, LuaSurface.create_entity allows to specify the name of the entity to be created -- is there any rule to determine whether

Code: Select all

surface.create_entity{ name = "car", position = {player.position.x - 1, player.position.y - 1} }
will create the car or the spider-vehicle?

Re: Entities with the same name

Posted: Wed Jul 20, 2022 3:42 pm
by Bilka
The internal name of that entity isn't car. Only the localised name is.
Image

Re: Entities with the same name

Posted: Wed Jul 20, 2022 3:59 pm
by Pi-C
Bilka wrote: Wed Jul 20, 2022 3:42 pm The internal name of that entity isn't car. Only the localised name is.
Oh, darn … I should have made that one more click! :-)

Also, this:

Code: Select all

local test = table.deepcopy(data.raw["spider-vehicle"]["spidertron"])
test.name = "car"
data:extend({test})
results in

Code: Select all

   3.501 Error ModManager.cpp:1558: Error while loading entity prototype "car" (spider-vehicle): Prototype "car" registered twice
So, the game already ensures that entity names will be unique even across entity types -- excellent! Anyway, thanks for the pointer, and sorry to waste your time! :mrgreen: