Detect entity Logistic Requester Chest and derivates ?
Detect entity Logistic Requester Chest and derivates ?
Hi,
while testing an entity in an event, I have to detect if it's a Logistic Requester Chest or a derivated object (created by another mod for example).
In order to deal with its request slots with get_request_slot.
But there is no "Logistic Requester Chest" type, just a "Logistic Container" type.
How can I detect if a Container Chest has Request Slots ? (i.e. is a Logistic Requester Chest or derivated)
Note that in data.lua, you have access to logistic_mode = "requester", that determinates the requester from the other "Logistic Containers"
while testing an entity in an event, I have to detect if it's a Logistic Requester Chest or a derivated object (created by another mod for example).
In order to deal with its request slots with get_request_slot.
But there is no "Logistic Requester Chest" type, just a "Logistic Container" type.
How can I detect if a Container Chest has Request Slots ? (i.e. is a Logistic Requester Chest or derivated)
Note that in data.lua, you have access to logistic_mode = "requester", that determinates the requester from the other "Logistic Containers"
My mods on the Factorio Mod Portal ![Geek :geek:](./images/smilies/icon_e_geek.gif)
![Geek :geek:](./images/smilies/icon_e_geek.gif)
Re: Detect entity Logistic Requester Chest and derivates ?
Not able to test but would something like this work?
isRequester, inSlot = pcall(entity.get_request_slot(1)) -- return true/false and simpleitemstack/error or error code.... maybe drop the inSlot and do that seperatly.
edit: Fixed typo, expanded
isRequester, inSlot = pcall(entity.get_request_slot(1)) -- return true/false and simpleitemstack/error or error code.... maybe drop the inSlot and do that seperatly.
edit: Fixed typo, expanded
Last edited by Nexela on Fri Jul 29, 2016 8:48 pm, edited 1 time in total.
Re: Detect entity Logistic Requester Chest and derivates ?
Yes, not very clean but pcall always works ![Wink ;-)](./images/smilies/icon_e_wink.gif)
I was hoping for something more regular.
![Wink ;-)](./images/smilies/icon_e_wink.gif)
I was hoping for something more regular.
My mods on the Factorio Mod Portal ![Geek :geek:](./images/smilies/icon_e_geek.gif)
![Geek :geek:](./images/smilies/icon_e_geek.gif)
Re: Detect entity Logistic Requester Chest and derivates ?
Having a has_request_slots or access to logistic mode would nice but pcall works wonders if used correctly.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Detect entity Logistic Requester Chest and derivates ?
Is there something on the entity.prototype you could test for? Alternatively, could you scan all the prototypes in data.raw when game starts and for any that meet your criteria add a flag to the prototype - that way you can later use entity.has_flag(your_flag) to detect if the entity is the required type before attempting entity.get_request_slot()
While pcall() will certainly work, it seems a very laggy way of doing things as in many cases an error will occur internally within the pcall() resulting in a stack trace.
IMO best solution would be to have a new entity.has_request_slots added to the API as suggested by @Nexela
While pcall() will certainly work, it seems a very laggy way of doing things as in many cases an error will occur internally within the pcall() resulting in a stack trace.
IMO best solution would be to have a new entity.has_request_slots added to the API as suggested by @Nexela
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Detect entity Logistic Requester Chest and derivates ?
Never thought about that to "transmit" informations from data.lua to control.lua when the API does not suppor the feature ! Nice idea, thx.that way you can later use entity.has_flag(your_flag)
My mods on the Factorio Mod Portal ![Geek :geek:](./images/smilies/icon_e_geek.gif)
![Geek :geek:](./images/smilies/icon_e_geek.gif)
Re: Detect entity Logistic Requester Chest and derivates ?
I added LuaEntity::request_slot_count read for 0.13.13.
If you want to get ahold of me I'm almost always on Discord.
Re: Detect entity Logistic Requester Chest and derivates ?
But will it be 0 on none-requester entities ? or will it trigger an error ? or at least return 0 on any logical-container that cannot request ?Rseding91 wrote:I added LuaEntity::request_slot_count read for 0.13.13.
because my initial purpose was to detect if any entity is a requester type.
My mods on the Factorio Mod Portal ![Geek :geek:](./images/smilies/icon_e_geek.gif)
![Geek :geek:](./images/smilies/icon_e_geek.gif)
Re: Detect entity Logistic Requester Chest and derivates ?
It's 0 if the entity doesn't have request slots. No errors.binbinhfr wrote:But will it be 0 on none-requester entities ? or will it trigger an error ? or at least return 0 on any logical-container that cannot request ?Rseding91 wrote:I added LuaEntity::request_slot_count read for 0.13.13.
because my initial purpose was to detect if any entity is a requester type.
If you want to get ahold of me I'm almost always on Discord.
Re: Detect entity Logistic Requester Chest and derivates ?
Nice ! Thx man.Rseding91 wrote:It's 0 if the entity doesn't have request slots. No errors.
My mods on the Factorio Mod Portal ![Geek :geek:](./images/smilies/icon_e_geek.gif)
![Geek :geek:](./images/smilies/icon_e_geek.gif)
Re: Detect entity Logistic Requester Chest and derivates ?
Hi Aubergine,aubergine18 wrote:Is there something on the entity.prototype you could test for? Alternatively, could you scan all the prototypes in data.raw when game starts and for any that meet your criteria add a flag to the prototype - that way you can later use entity.has_flag(your_flag) to detect if the entity is the required type before attempting entity.get_request_slot()
While pcall() will certainly work, it seems a very laggy way of doing things as in many cases an error will occur internally within the pcall() resulting in a stack trace.
IMO best solution would be to have a new entity.has_request_slots added to the API as suggested by @Nexela
did you ever try this ?
because trying to add a custom flag does not work for me :
Code: Select all
for _, inserter in pairs(data.raw["inserter"]) do
if inserter.filter_count and inserter.filter_count > 0 then
if not inserter.flags then inserter.flags = {} end
table.insert(inserter.flags,"my_filter")
end
end
so apparently factorio only support its own flags...
could you tell me if I made a mistake ?
My mods on the Factorio Mod Portal ![Geek :geek:](./images/smilies/icon_e_geek.gif)
![Geek :geek:](./images/smilies/icon_e_geek.gif)
Re: Detect entity Logistic Requester Chest and derivates ?
Good morning Rseding,
In the same order of idea, it would be great to have a
filter_slot_count :: uint [R] The number of filter slots this entity has. (0 if none or non applicable)
In the same order of idea, it would be great to have a
filter_slot_count :: uint [R] The number of filter slots this entity has. (0 if none or non applicable)
My mods on the Factorio Mod Portal ![Geek :geek:](./images/smilies/icon_e_geek.gif)
![Geek :geek:](./images/smilies/icon_e_geek.gif)
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Detect entity Logistic Requester Chest and derivates ?
Nope, having done some additional digging it seems that flags are limited to those the game defines rather than an open-ended dictionary of strings.binbinhfr wrote: Hi Aubergine,
did you ever try this ?
because trying to add a custom flag does not work for me :
![Sad :(](./images/smilies/icon_e_sad.gif)
Now that the new property is added in latest release it should be easier to detect the requester chests, but there's still no easy way to group certain types of entities based on any abstract criteria.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Detect entity Logistic Requester Chest and derivates ?
If entity prototype flags was a simple collection of strings that would increase the memory usage by a large amount and slow down checking them by an even larger amount since the entire contents of each string would need to be checked against every string on the entity prototype.
As it is now it's a simple bitmask and 1 bitwise operation to check if an entity has a flag defined - no memory allocations and no iterating to check.
As it is now it's a simple bitmask and 1 bitwise operation to check if an entity has a flag defined - no memory allocations and no iterating to check.
If you want to get ahold of me I'm almost always on Discord.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Detect entity Logistic Requester Chest and derivates ?
@Rseding91: Agreed, bitmasks are much faster and efficient to work with, and certainly the best choice for the factorio flag taxonomy.
Would it be possible to expose the flags bitmask to the API? That way we could use the Bit32 library - eg. to check for multiple flags in a single operation, rather than multiple has_flag() calls.
Also, Strings in Lua aren't quite as bad as you're making out (still slower and more crufty than bitmasks obviously)...
From Lua GC docs:
Would it be possible to get a .tags property on prototypes (and corresponding .has_tag() method on entities for lazy evaluation) so we can create custom folksonomies? While still slow, compared to bitmasks, it will greatly simplify many situations. For example, last night I was looking at the code for Nixie tubes mod, and there's three entities involved - currently that requires up to 3 string comparisons (well, the numeric index of those strings in the string pool) to determine if an entity is a nixie tube. By having a folksonomy, that would be reduced to a single comparison of a tag.
Would it be possible to expose the flags bitmask to the API? That way we could use the Bit32 library - eg. to check for multiple flags in a single operation, rather than multiple has_flag() calls.
Also, Strings in Lua aren't quite as bad as you're making out (still slower and more crufty than bitmasks obviously)...
From Lua GC docs:
A table of strings is actually a table of indices of those strings in the central string pool. When comparing strings, Lua actually compares their indices rather than the strings themselves. This means that string length and content has no bearing on the performance of operations that compare strings; it's as fast as comparing two numbers.Lua has unique strings, that means that each possible string exists only once within Lua. If a new string occurs Lua first checks if it already exists within the string pool. If it does, a reference to that older string is used. If it does not exist, a new string object is created and put into the string pool. The GC checks the string pool for unused strings and frees them.
Would it be possible to get a .tags property on prototypes (and corresponding .has_tag() method on entities for lazy evaluation) so we can create custom folksonomies? While still slow, compared to bitmasks, it will greatly simplify many situations. For example, last night I was looking at the code for Nixie tubes mod, and there's three entities involved - currently that requires up to 3 string comparisons (well, the numeric index of those strings in the string pool) to determine if an entity is a nixie tube. By having a folksonomy, that would be reduced to a single comparison of a tag.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Detect entity Logistic Requester Chest and derivates ?
I totally second this !Would it be possible to get a .tags property on prototypes (and corresponding .has_tag() method on entities for lazy evaluation) so we can create custom folksonomies?
My mods on the Factorio Mod Portal ![Geek :geek:](./images/smilies/icon_e_geek.gif)
![Geek :geek:](./images/smilies/icon_e_geek.gif)
Re: Detect entity Logistic Requester Chest and derivates ?
Rseding,
Me again! but don't get angry![Smile :)](./images/smilies/icon_e_smile.gif)
Thanks for adding in the request_slot_count
but I have come across a problem and having luaentityprototype read for logistic_mode would come in handy. As always thanks for everything you and all the other devs do to keep this game awesome!
Me again! but don't get angry
![Smile :)](./images/smilies/icon_e_smile.gif)
Thanks for adding in the request_slot_count
but I have come across a problem and having luaentityprototype read for logistic_mode would come in handy. As always thanks for everything you and all the other devs do to keep this game awesome!