So now, I am making an official request for an API for accessing the entity state, whether it is enabled or disabled, based on its logistic network condition, circuit network operation mode and circuit network condition. It will be useful for transport belts and inserters.
Long story short, I have asked about the same thing here: viewtopic.php?f=25&t=27724. I came up with a snippet and used it in Creative Mode. However, during my battle against the performance issue, I found out that "control.circuit_condition" has poor performance that you can really see the FPS difference when you have quite a number of Item Sources/Item Voids/Duplicators unwired vs wired.
78 Item Voids - unwired = 60 FPS vs wired = 52 FPS
Providing an API like "LuaEntity.enabled" can solve 2 problems:
1) no more custom snippets. Different mods can use the same piece of code. Elegant. Tiny. Clean and tidy.
2) performance should be much better.
API for accessing the entity state (enabled/disabled)
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: API for accessing the entity state (enabled/disabled)
Would this also factor in things like power state (eg. connected but insufficient power) or would that be separate?
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: API for accessing the entity state (enabled/disabled)
Added for 0.13.16.
If you want to get ahold of me I'm almost always on Discord.
Re: API for accessing the entity state (enabled/disabled)
hm... I didn't think of power, because my entities don't require that.aubergine18 wrote:Would this also factor in things like power state (eg. connected but insufficient power) or would that be separate?
Wow, thanks! I didn't expect to have response so quickly!Rseding91 wrote:Added for 0.13.16.
Re: API for accessing the entity state (enabled/disabled)
Hi Rseding91, since you are (were) here, would you mind also take a look on this request? on_player_opened/on_player_closed
I guess it would be easy to be implemented on your side? Maybe just invoke the lua events when the entity's GUI is opened / close?
I guess it would be easy to be implemented on your side? Maybe just invoke the lua events when the entity's GUI is opened / close?
Re: API for accessing the entity state (enabled/disabled)
is the new API "LuaControlBehavior::disabled" ?
I can't get it to work. It always returns false....
I changed the snippet to this:
[code]function is_inserter_enabled(inserter)
local control = inserter.get_control_behavior()
-- Does it have control behaviour? (Not connected = no control?)
if control and control.valid then
-- New API from Factorio 0.13.16
if control.disabled == nil then
print_to_all_players("Is control disabled? nil")
else
if control.disabled then
print_to_all_players("Is control disabled? true")
return false
else
print_to_all_players("Is control disabled? false")
return true
end
end
end
-- No control? Because not connected to network?
return true
end[/code]
Only "Is control disabled? false" is printed no matter I connect the wire, disconnect the wire, set condition or unset condition.
In case you need print_to_all_players to test:
[code]-- Prints the given message to all players.
function print_to_all_players(message)
for _, player in pairs(game.players) do
player.print(message)
end
end[/code]
Am I doing something wrong?
Edit: fixed. It is LuaGenericOnOffControlBehavior.disabled. Thanks.