[2.0.11] Buggy on_built_entity event for 'smart' underground belt placement

Bugs that are actually features.
kelianmao
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Jan 14, 2021 5:52 pm
Contact:

[2.0.11] Buggy on_built_entity event for 'smart' underground belt placement

Post by kelianmao »

on_built_entity has buggy behavior when pairs of underground belts are built using the new 'smart' belt logic, especially when one of the undergrounds is destroyed.

A short debug print function in control.lua:

Code: Select all

local function on_built_entity(event)
  game.print(event.tick)
  game.print(event.entity.name)
  game.print(event.entity.position)
  game.print(event.entity.belt_to_ground_type)
  -- event.entity.destroy()
end
script.on_event(defines.events.on_built_entity, on_built_entity, {{filter="type", type="underground-belt"}})

When the pair of undergrounds is built, you expect this script event to trigger twice. But instead, you get one merged trigger of the event, somehow printing the event once but both the belts separately.
on_built1.png
on_built1.png (89.58 KiB) Viewed 651 times

It gets even weirder when you add an entity.destroy() call, where it seems to bug out the second underground belt's construction, and the response is incomplete.
on_built2.png
on_built2.png (86.13 KiB) Viewed 651 times
Somehow now only the position gets printed, and the belt_to_ground_type of the second underground is gone. Since you don't get the info that the second belt is an output belt, belt directions are all wrong.
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 468
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [2.0.11] Buggy on_built_entity event for 'smart' underground belt placement

Post by Stringweasel »

This is most likely just the print function skipping duplicate messages to prevent spamming. Try setting `skip = defines.print_skip.never` in the `print_settings`. https://lua-api.factorio.com/latest/cla ... html#print
Alt-F4 Author | Factorio Modder
Probably known for: (Configurable) Valves | Better Victory Screen | Space Spidertron | Fluidic Power
Official Contributor to Space Exploration
kelianmao
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Jan 14, 2021 5:52 pm
Contact:

Re: [2.0.11] Buggy on_built_entity event for 'smart' underground belt placement

Post by kelianmao »

Found further bugginess. Here are 3 cases, built right to left.
on_built3.png
on_built3.png (1.37 MiB) Viewed 640 times
- First one (right), built manually, you see the two triggers, and the input/output are correct.
- Second (middle), auto-built from the bottom, ie forward, the input/output match the manual placement.
- Third (left), auto-built from above, ie against the direction of the belt, the printed input/output directions are wrong. The y=-22.5 belt should be input, and vise versa.

It looks like there might be manual logic (in cpp?) that is correcting the direction of the underground belts, but it is happening after the on_built_entity event has already fired.
kelianmao
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Jan 14, 2021 5:52 pm
Contact:

Re: [2.0.11] Buggy on_built_entity event for 'smart' underground belt placement

Post by kelianmao »

Stringweasel wrote: Wed Oct 30, 2024 8:04 am This is most likely just the print function skipping duplicate messages to prevent spamming. Try setting `skip = defines.print_skip.never` in the `print_settings`. https://lua-api.factorio.com/latest/cla ... html#print
Ok, indeed it was skipping duplicate messages. But the issue instead is that both underground belts (with .destroy()) are being placed as input belts, hence the deduplication triggering. So it is still buggy (I originally noticed the issue when using the fields, the printing was just to debug).
on_built4.png
on_built4.png (128.74 KiB) Viewed 638 times
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 468
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [2.0.11] Buggy on_built_entity event for 'smart' underground belt placement

Post by Stringweasel »

kelianmao wrote: Wed Oct 30, 2024 7:50 am A short debug print function in control.lua:
Did you add the print settings I mentioned? You're basing your assumptions on incomplete data.

And might I suggest:

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
  game.print(serpent.block(event), { skip = defines.print_skip.never })
end, {{filter="type", type="underground-belt"}})
Or even better, step through the code using the Factorio Modding Toolkit extension in VSCode.
Alt-F4 Author | Factorio Modder
Probably known for: (Configurable) Valves | Better Victory Screen | Space Spidertron | Fluidic Power
Official Contributor to Space Exploration
kelianmao
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Jan 14, 2021 5:52 pm
Contact:

Re: [2.0.11] Buggy on_built_entity event for 'smart' underground belt placement

Post by kelianmao »

Yes, the last screenshot is with never skip. Besides, I found the bug when using the fields for other functions, not when printing, I only started printing when I was getting unexpected behaviour.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15878
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.11] Buggy on_built_entity event for 'smart' underground belt placement

Post by Rseding91 »

Thanks for the report. This is working correctly, until both belts are fully built the input vs output type of the belts are not fully configured.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Not a bug”