Page 1 of 1

API for accessing the entity state (enabled/disabled)

Posted: Mon Aug 08, 2016 6:31 pm
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.

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

Posted: Mon Aug 08, 2016 6:46 pm
by aubergine18
Would this also factor in things like power state (eg. connected but insufficient power) or would that be separate?

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

Posted: Mon Aug 08, 2016 11:31 pm
by Rseding91
Added for 0.13.16.

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

Posted: Tue Aug 09, 2016 1:37 am
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

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

Posted: Tue Aug 09, 2016 2:14 am
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?

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

Posted: Wed Aug 17, 2016 5:04 pm
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