So, despite having written a mod for Factorio I still struggle a lot with the concept of prototypes in the game and what that actually "means" (my mod didn't deal with too much custom prototype stuff, etc. hence why I think I was able to 'sneak by').
In a new mod I'm working on, I want to basically do an "instance of" check:
Code: Select all
for (thisEntity : list of entities) {
if (thisEntity.prototype instanceof "whatever") {
-- do stuff
}
}
1. Maybe "whatever" is an abstract prototype built into the game and I don't care to hard code a list of all possible concrete 'names' using that abstract prototype?
- Granted, it looks like the inheritance tree is available in the game's API so maybe you could iterate over all subclass names and check .name == entry for each entry? Seems ugly though...
2. What happens if another mod deepcopy's an existing prototype (that I care about), adds a custom thing with the same/similar behavior, etc. And maybe I still want my logic to try to handle that "inheriting" prototype? I assume anything that's deepcopy()'d still has a duplicate of the original prototype's Lua APIs in the entity's .prototype property?
What's the proper way to handle an 'instanceof' type check like this? Or (more likely) where is my understanding of prototype trees/inheritance incorrect?
Thanks!
