[0.17.79] defines.events.on_robot_built_entity sometimes doesn't fire under certain circumstances

Place to get help with not working mods / modding interface.
Yehn
Fast Inserter
Fast Inserter
Posts: 111
Joined: Tue Jul 12, 2016 3:45 am
Contact:

[0.17.79] defines.events.on_robot_built_entity sometimes doesn't fire under certain circumstances

Post by Yehn »

defines.events.on_robot_built_entity doesn't always fire when there is a large number of queued robot construction tasks.

[*] It is possible that the bug below can also only occur after a large number of robot deconstruction tasks have been processed, I haven't been able to determine this for certain.

Here is the relevant code blocks from the mod:

Code: Select all

script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity, defines.events.script_raised_built}, siphonbuilt)

Code: Select all

function siphonbuilt(event)
	local ent = event.created_entity
	if not ent then return end 
	if ent.name ~= "ore-siphon" then return end
	local surface = ent.surface
	global.siphons[ent.unit_number] = {siphonent = ent, recipe = nil, ore = nil, ingredient = nil, table_res = {}, search = true}
	table.insert(global.siphons_index, ent.unit_number)
	log("added: " .. ent.unit_number)
	if global.siphon_range[ent.force.index] == nil then
		global.siphon_range[ent.force.index] = 15
	end
end
The log() line is a recent addition when I became suspicious that there was a malfunction. I noticed after constructing a large number of entities with robot construction, some of the buildings did not become active. Entering debug mode, I looked for the unit number of one of the inactive buildings.
For example, 30126
Image

Excerpt from the log file:

Code: Select all

1082.848 Script @__ResourceSiphon__/control.lua:22: added: 30043
1082.849 Script @__ResourceSiphon__/control.lua:22: added: 30045
1082.998 Script @__ResourceSiphon__/control.lua:22: added: 30052
1083.049 Script @__ResourceSiphon__/control.lua:22: added: 30056
1083.114 Script @__ResourceSiphon__/control.lua:22: added: 30059
1083.183 Script @__ResourceSiphon__/control.lua:22: added: 30063
1083.231 Script @__ResourceSiphon__/control.lua:22: added: 30067
1083.315 Script @__ResourceSiphon__/control.lua:22: added: 30071
1083.331 Script @__ResourceSiphon__/control.lua:22: added: 30075
1083.348 Script @__ResourceSiphon__/control.lua:22: added: 30078
1083.565 Script @__ResourceSiphon__/control.lua:22: added: 30101
1083.581 Script @__ResourceSiphon__/control.lua:22: added: 30102
1083.649 Script @__ResourceSiphon__/control.lua:22: added: 30105
1083.817 Script @__ResourceSiphon__/control.lua:22: added: 30117
1084.064 Script @__ResourceSiphon__/control.lua:22: added: 30135
1084.065 Script @__ResourceSiphon__/control.lua:22: added: 30137
1084.197 Script @__ResourceSiphon__/control.lua:22: added: 30147
1084.348 Script @__ResourceSiphon__/control.lua:22: added: 30159
1084.383 Script @__ResourceSiphon__/control.lua:22: added: 30160
1084.483 Script @__ResourceSiphon__/control.lua:22: added: 30171
1084.514 Script @__ResourceSiphon__/control.lua:22: added: 30172
1084.531 Script @__ResourceSiphon__/control.lua:22: added: 30173
1084.634 Script @__ResourceSiphon__/control.lua:22: added: 30179
1084.699 Script @__ResourceSiphon__/control.lua:22: added: 30181
1084.715 Script @__ResourceSiphon__/control.lua:22: added: 30183
1084.816 Script @__ResourceSiphon__/control.lua:22: added: 30192
1084.915 Script @__ResourceSiphon__/control.lua:22: added: 30195
1084.983 Script @__ResourceSiphon__/control.lua:22: added: 30197
1085.282 Script @__ResourceSiphon__/control.lua:22: added: 30215
1085.382 Script @__ResourceSiphon__/control.lua:22: added: 30220
1085.382 Script @__ResourceSiphon__/control.lua:22: added: 30221
And it is not simply out of order - ctrl F shows it is not there at all.

What's more, I am able to consistently reproduce this. Steps to reproduce as follows.

1. Mod sync to the attached save. Do not use Resource Siphon from the mod portal, unless you feel you don't need the extra debug logs.
2. A. Deconstruct the outer four columns of each side, using the deconstruction planner.
Image
Image

2. B. It should then look like this:
Image

3. Select the leftmost blueprint.
Image

4. In quick succession, replace all the deconstructed columns.
Note: If all the blueprints are not placed quickly, the issue will not be reproduced.
Image

5. Once construction has finished, we look closely for any machines that haven't activated. In this case, 26118 is one of them.
Image

6. If we go to factorio-current.log, press ctrl F, and search for 26118, we will get no results. If we scroll to around where 26xxx entities are logged, we see:

Code: Select all

7983.200 Script @__ResourceSiphon__/control.lua:22: added: 26061
7983.220 Script @__ResourceSiphon__/control.lua:22: added: 26068
7983.249 Script @__ResourceSiphon__/control.lua:22: added: 26073
7983.316 Script @__ResourceSiphon__/control.lua:22: added: 26085
7983.332 Script @__ResourceSiphon__/control.lua:22: added: 26086
7983.332 Script @__ResourceSiphon__/control.lua:22: added: 26087
7983.366 Script @__ResourceSiphon__/control.lua:22: added: 26091
7983.416 Script @__ResourceSiphon__/control.lua:22: added: 26097
7983.431 Script @__ResourceSiphon__/control.lua:22: added: 26100
7983.467 Script @__ResourceSiphon__/control.lua:22: added: 26106
7983.500 Script @__ResourceSiphon__/control.lua:22: added: 26111
7984.500 Script @__ResourceSiphon__/control.lua:22: added: 26119
7984.565 Script @__ResourceSiphon__/control.lua:22: added: 26124
7984.582 Script @__ResourceSiphon__/control.lua:22: added: 26127
7984.614 Script @__ResourceSiphon__/control.lua:22: added: 26130
7984.781 Script @__ResourceSiphon__/control.lua:22: added: 26139
7984.897 Script @__ResourceSiphon__/control.lua:22: added: 26148
7984.914 Script @__ResourceSiphon__/control.lua:22: added: 26149
7984.983 Script @__ResourceSiphon__/control.lua:22: added: 26156
7985.032 Script @__ResourceSiphon__/control.lua:22: added: 26166
7985.081 Script @__ResourceSiphon__/control.lua:22: added: 26171
7985.165 Script @__ResourceSiphon__/control.lua:22: added: 26178
7985.181 Script @__ResourceSiphon__/control.lua:22: added: 26182
7985.230 Script @__ResourceSiphon__/control.lua:22: added: 26187
7985.265 Script @__ResourceSiphon__/control.lua:22: added: 26189
7985.281 Script @__ResourceSiphon__/control.lua:22: added: 26190
The entity is missing. For some reason, the event did not fire when that one was constructed.
Attachments
oretest_angelbob2.zip
Save file used in examples
(4.5 MiB) Downloaded 93 times
ResourceSiphon_0.17.9.zip
Debug version of ResourceSiphon
(3.35 MiB) Downloaded 99 times
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5286
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.17.79] defines.events.on_robot_built_entity sometimes doesn't fire under certain circumstances

Post by Klonan »

I am most likely to believe this is a scripting error rather than a game engine issue

The robot event has been in the game for a very long time, use in very many mods and scripts, and no issue has ever been reported with it
Yehn
Fast Inserter
Fast Inserter
Posts: 111
Joined: Tue Jul 12, 2016 3:45 am
Contact:

Re: [0.17.79] defines.events.on_robot_built_entity sometimes doesn't fire under certain circumstances

Post by Yehn »

Klonan wrote: Sun Dec 15, 2019 1:55 pm I am most likely to believe this is a scripting error rather than a game engine issue

The robot event has been in the game for a very long time, use in very many mods and scripts, and no issue has ever been reported with it
The conditions that need to be met to write to the log file are pretty simple:
  • Created entity is not nil
  • created entity is "ore-siphon"
I don't see a lot of room here for a scripting error, but if it is an error in the script, please let me know.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14339
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.17.79] defines.events.on_robot_built_entity sometimes doesn't fire under certain circumstances

Post by Rseding91 »

Thanks for the report however I don't believe there's any bug here. The event doesn't care if you fire 1 per 2 weeks or 5 million in a single frame - they all get fired every time.

I'm going to move this to modding help until it can be proven that there's anything going wrong on the games side.
If you want to get ahold of me I'm almost always on Discord.
Yehn
Fast Inserter
Fast Inserter
Posts: 111
Joined: Tue Jul 12, 2016 3:45 am
Contact:

Re: [0.17.79] defines.events.on_robot_built_entity sometimes doesn't fire under certain circumstances

Post by Yehn »

Rseding91 wrote: Mon Dec 16, 2019 6:28 pm Thanks for the report however I don't believe there's any bug here. The event doesn't care if you fire 1 per 2 weeks or 5 million in a single frame - they all get fired every time.

I'm going to move this to modding help until it can be proven that there's anything going wrong on the games side.
Please reconsider.

There's very little code involved with logging the event.

You could simplify it to something like this:

Code: Select all

function siphonbuilt(event)
	local ent = event.created_entity
	if not ent or ent.name ~= "ore-siphon" then return end
	log("added: " .. ent.unit_number)
end

script.on_event(defines.events.on_robot_built_entity, siphonbuilt)
You need only 7 lines of code (well, 6 not counting the space) to prove there is a bug where the event does not always fire.

Everything else just makes it easier to find, but if you want to go through each built entity's unit number manually and see that no event fired for some of them, you can do this.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5286
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.17.79] defines.events.on_robot_built_entity sometimes doesn't fire under certain circumstances

Post by Klonan »

Yehn wrote: Tue Dec 17, 2019 9:52 am
You need only 7 lines of code (well, 6 not counting the space) to prove there is a bug where the event does not always fire.

Everything else just makes it easier to find, but if you want to go through each built entity's unit number manually and see that no event fired for some of them, you can do this.
Well, you also have a ton of other mods installed, they could be interfering in any number of ways
Yehn
Fast Inserter
Fast Inserter
Posts: 111
Joined: Tue Jul 12, 2016 3:45 am
Contact:

Re: [0.17.79] defines.events.on_robot_built_entity sometimes doesn't fire under certain circumstances

Post by Yehn »

Klonan wrote: Tue Dec 17, 2019 11:27 am
Yehn wrote: Tue Dec 17, 2019 9:52 am
You need only 7 lines of code (well, 6 not counting the space) to prove there is a bug where the event does not always fire.

Everything else just makes it easier to find, but if you want to go through each built entity's unit number manually and see that no event fired for some of them, you can do this.
Well, you also have a ton of other mods installed, they could be interfering in any number of ways
I'm sorry, it looks like you're right. It seems another mod was interfering.

I don't normally play with those mods, it was just the set that a bug report came in using.
Post Reply

Return to “Modding help”