API for accessing the entity state (enabled/disabled)

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

API for accessing the entity state (enabled/disabled)

Post by Mooncat »

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.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: API for accessing the entity state (enabled/disabled)

Post by aubergine18 »

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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14280
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: API for accessing the entity state (enabled/disabled)

Post by Rseding91 »

Added for 0.13.16.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: API for accessing the entity state (enabled/disabled)

Post by Mooncat »

aubergine18 wrote:Would this also factor in things like power state (eg. connected but insufficient power) or would that be separate?
hm... I didn't think of power, because my entities don't require that. :mrgreen:

Rseding91 wrote:Added for 0.13.16.
Wow, thanks! I didn't expect to have response so quickly! :D
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: API for accessing the entity state (enabled/disabled)

Post by Mooncat »

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?
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: API for accessing the entity state (enabled/disabled)

Post by Mooncat »

Hi Rseding91,

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. :D
Post Reply

Return to “Implemented mod requests”