[1.1.2][Modding]event 'on_gui_opened' contains different entities if requests are configured in a logistic chest or not

Place to get help with not working mods / modding interface.
Post Reply
Daeruun
Inserter
Inserter
Posts: 40
Joined: Thu May 04, 2017 8:37 pm
Contact:

[1.1.2][Modding]event 'on_gui_opened' contains different entities if requests are configured in a logistic chest or not

Post by Daeruun »

Hi guys,

I'm not 100% sure this is a bug or a feature, but I'm quite sure it was different in 1.0 and I could not find a changelog-entry on this.

Whilst messing around with my code and some chests I found that the event 'on_gui_opened' behaves differently if a requester/buffer chest contains requests or not.
Might be the same with other entities that provide request-slots.

If requests are configured, the entities player and inventory can be extracted.
If NO requests are configured these two entities are 'nil'.
'entity' seems to exist if anything other than the player-inventory is opened.

I'm quite but not absolutely sure this was different before 1.1.x

test-code:

Code: Select all

script.on_event(defines.events.on_gui_opened, function(event)
	local player, inventory = get_event_entities(event) -- missing both entities if chest without configured requests
	
	game.players[1].print ("on_gui_opened:")
	if (player) then 							-- exists if player-inventory or chest with configured requests opened, otherwise nil
		game.players[1].print ("player.name: '" .. serpent.line(player.name) .. "'")
	end
	if (inventory) then 							-- exists if player-inventory or chest with configured requests opened, otherwise nil
		game.players[1].print ("inventory.name: '" .. serpent.line(inventory.name) .. "'")
	end
	if (event.entity) then							-- nil if player-inventory opened, exists if another entity is opened
		game.players[1].print ("event.entity.name: '" .. serpent.line(event.entity.name).. "'")
	end
end)
is there a way to detect an entity with request-slots?
'event.entity.request_slot_count' returns '0' regardless if I open a requester chest (without pre defined requests) or a storage-chest for example...

best regards,
Daeruun

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 1578
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.2][Modding]event 'on_gui_opened' contains different entities if requests are configured in a logistic chest or

Post by boskid »

Cannot reproduce what you described.

With simple testing code:

Code: Select all

/c script.on_event(defines.events.on_gui_opened, function(e) log(e.entity.name..": "..(e.entity.request_slot_count or 0).." "..serpent.line(e)) end)
and using some buffer and requester chests with and without requests i have this:
342.546 Script =(command):1: logistic-chest-storage: 0 {entity = {__self = "userdata"}, gui_type = 1, name = 84, player_index = 1, tick = 8487}
343.096 Script =(command):1: logistic-chest-buffer: 0 {entity = {__self = "userdata"}, gui_type = 1, name = 84, player_index = 1, tick = 8520}
343.547 Script =(command):1: logistic-chest-requester: 0 {entity = {__self = "userdata"}, gui_type = 1, name = 84, player_index = 1, tick = 8547}
344.064 Script =(command):1: logistic-chest-storage: 0 {entity = {__self = "userdata"}, gui_type = 1, name = 84, player_index = 1, tick = 8578}
344.548 Script =(command):1: logistic-chest-buffer: 4 {entity = {__self = "userdata"}, gui_type = 1, name = 84, player_index = 1, tick = 8607}
345.098 Script =(command):1: logistic-chest-requester: 4 {entity = {__self = "userdata"}, gui_type = 1, name = 84, player_index = 1, tick = 8640}
All of them contain valid player index. How is get_event_entities function defined?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5201
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [1.1.2][Modding]event 'on_gui_opened' contains different entities if requests are configured in a logistic chest or

Post by eradicator »

Sounds like your "get_event_entities()" function broken due to the changes made to the logistic request api.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Daeruun
Inserter
Inserter
Posts: 40
Joined: Thu May 04, 2017 8:37 pm
Contact:

Re: [1.1.2][Modding]event 'on_gui_opened' contains different entities if requests are configured in a logistic chest or

Post by Daeruun »

arg. sorry boskid
of course that function does not work anymore. damn.

what broke my neck was this line:

Code: Select all

if not (entity and entity.request_slot_count > 0) then return nil end
entity is valid, but as mentioned before, 'entity.request_slot_count' returns '0' regardless if I open a requester chest (without pre defined requests) or a storage-chest for example...


is there a clever way to check if a given entity has requester-abilities?
on chests one can use

Code: Select all

requester = (entity.prototype.logistic_mode == 'buffer') or (entity.prototype.logistic_mode == 'requester')
but that does not work on vehicles or charakters...

I played around with

Code: Select all

local slot = entity.get_request_slot(1)
but that throws an exception if tried on anything that does not have request-slots...

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [1.1.2][Modding]event 'on_gui_opened' contains different entities if requests are configured in a logistic chest or

Post by Choumiko »

Currently i use

Code: Select all

entity.get_logistic_point(defines.logistic_member_index.character_requester)
to check if a spidertron/character can have logistic requests set
For characters this has worked for a long time, i added spidertrons recently and maybe got lucky that character_requester works

Daeruun
Inserter
Inserter
Posts: 40
Joined: Thu May 04, 2017 8:37 pm
Contact:

Re: [1.1.2][Modding]event 'on_gui_opened' contains different entities if requests are configured in a logistic chest or

Post by Daeruun »

Thanks a lot, Choumiko, that seems to work nicely - can be used for chests as well, and I'm optimistic it will work on modded entities as well.

with

Code: Select all

defines.logistic_member_index = { logistic_container=0, vehicle_storage=1, character_requester=0, character_storage=1, character_provider=2, generic_on_off_behavior=0, }
and

Code: Select all

local logistic_point = entity.get_logistic_point(defines.logistic_member_index.character_requester)

Code: Select all

logistic_point.mode
can be used to select every kind of logistic function checking against this:

Code: Select all

defines.logistic_mode={ none=0, active_provider=1, storage=2, requester=3, passive_provider=4, buffer=5, }
perhaps logistic_member_index should be extended by vehicle_requester=0, vehicle_provider=2 to prevent confusion or to make clear that this works correctly/as intended?

Post Reply

Return to “Modding help”