Page 1 of 1

[Twinsen] [0.14.0] LuaControlBehavior::disabled not work for inserter

Posted: Fri Aug 19, 2016 11:04 pm
by Mooncat
First of all, is LuaControlBehavior::disabled for detecting whether the entity (e.g. inserter) is disabled due to circuit signals? If not, then I got it wrong and it is not a bug. :P
(But then I will need an answer for this: [Implemented request] API for accessing the entity state (enabled/disabled))

Otherwise, please read:
This property always returns false no matter I wire or unwire the entity and set or unset conditions.

I am using this snippet to check whether my inserter entity is working:

Code: Select all

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
I call this function in every tick.
If the entity has not been wired since it was placed, nothing is printed as expected.
But once the entity is wired, "Is control disabled? false" is printed. But I expected "Is control disabled? true" because vanilla inserters are disabled once they are wired without conditions.
Then, no matter I set or unset conditions, as well as unwire or wire again, the same message is printed.

In case you need print_to_all_players:

Code: Select all

function print_to_all_players(message)
   for _, player in pairs(game.players) do
      player.print(message)
   end
end

Re: [0.13.17] LuaControlBehavior::disabled always returns false

Posted: Sat Aug 20, 2016 1:19 am
by Rseding91
The inserters aren't disabled because of the condition. They have no work to do because of the condition but the condition is not preventing the inserter from trying to do work.

The disabled read returns true when the condition its self disables the entity - the "enable/disable" radio option in an entity control behavior GUI.

An example: enable/disable transport belt when condition isn't met.

Re: [0.13.17] LuaControlBehavior::disabled always returns false

Posted: Sat Aug 20, 2016 8:20 am
by Mooncat
Rseding91 wrote:The inserters aren't disabled because of the condition. They have no work to do because of the condition but the condition is not preventing the inserter from trying to do work.

The disabled read returns true when the condition its self disables the entity - the "enable/disable" radio option in an entity control behavior GUI.

An example: enable/disable transport belt when condition isn't met.
Sorry, but I am not quite understand...
I have already set "enable/disable" operation mode for the inserter, and the red light of the circuit connector is on.
Or did I miss something that the inserter can actually work under special circumstances? :shock:
dontunderstand.png
dontunderstand.png (161.07 KiB) Viewed 6279 times
Before: when I use my old snippet, it stops generating iron plates right after I connect it with wire.
After: now I use LuaControlBehavior::disabled, but it never stops even if I set condition to it.

I tested it on transport belt, it works like how you said:
transportbelt.png
transportbelt.png (237.23 KiB) Viewed 6279 times
It is disabled right after I connect it with wire. (The 1-tick delay is fine.)

But it doesn't work like how I expected when I test it on inserter, with or without energy:
inserter.png
inserter.png (227.52 KiB) Viewed 6279 times
My little mod for testing:
luacontrolbehavior-disabled_0.0.1.zip
(1.24 KiB) Downloaded 162 times
(It just registers entities, then iterates them in every tick and prints messages.)

Re: [0.13.17] LuaControlBehavior::disabled not work for inserter

Posted: Thu Aug 25, 2016 5:31 pm
by Mooncat
Hi, any news on this bug or ... not-my-expected implementation?

I have updated to 0.13.18 but this is still the same.
Maybe I should request another API? Because I want to know when the inserter is disabled. :?

Re: [0.14.0] LuaControlBehavior::disabled not work for inserter

Posted: Fri Aug 26, 2016 4:17 pm
by Mooncat
Updated the mod for testing to support Factorio 0.14.
Still waiting for the answer. :)
luacontrolbehavior-disabled_0.0.2.zip
(1.24 KiB) Downloaded 139 times

Re: [0.14.0] LuaControlBehavior::disabled not work for inserter

Posted: Tue Aug 30, 2016 1:46 pm
by Klonan
I think i have confirmed the,

Inserter never reads true on get_control_behaviour().disabled,
Whether logistic condition, circuit condition or otherwise



In this case, one condition is true, the other is false. Both control settings read disabled as false.

Re: [0.14.0] LuaControlBehavior::disabled not work for inserter

Posted: Wed Aug 31, 2016 5:32 am
by Mooncat
Thanks for the reply and confirmation!
Now I know it is a bug and can patiently wait for the fix. :D

Re: [Twinsen] [0.14.0] LuaControlBehavior::disabled not work for inserter

Posted: Fri Sep 02, 2016 1:12 pm
by Twinsen
Fixed in Version: 0.14.3

Also Moved LuaControlBehavior::disabled to LuaGenericOnOffControlBehavior::disabled

Re: [Twinsen] [0.14.0] LuaControlBehavior::disabled not work for inserter

Posted: Fri Sep 02, 2016 1:43 pm
by Mooncat
Thanks a lot! <3