on_player_main_inventory_changed unreliable

Bugs that are actually features.
Post Reply
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

on_player_main_inventory_changed unreliable

Post by ownlyme »

I'm trying to determine when a bot takes an item out of my hand
To achieve this, i registered some events for on_player_main_inventory_changed, on_player_cursor_stack_changed and on_player_fast_transferred
Then i wrote an on_tick script that compares the last-registered on_player_main_inventory_changed and on_player_cursor_stack_changed ticks and makes sure the player didn't fast-transfer something on the same tick.
But when i proceeded to test my system with concrete, i often got items taken out of my hand without the scripts noticing. (randomly)
After further investigation, i found out that the on_player_main_inventory_changed event didn't fire reliably
I also disabled all other mods to make sure no other mod was swallowing the events, like when a mod destroys a robot on a robot_built event.

i attached the mods, to test you might need to sell a few reactors for some money first and toggle the checkbox next to the red + green buttons in the crafting menu

let me know if you need more information or different testing methods

i dont remember anymore why i monitored both events but it looks like i can solve my problem without the main_inventory_changed event.
still it would be really nice if all events were reliable
Attachments
market2_autobuy_0.17.1.zip
(39.34 KiB) Downloaded 59 times
market2_0.17.13.zip
(3.16 MiB) Downloaded 54 times
Screenshot_3.jpg
Screenshot_3.jpg (40.48 KiB) Viewed 1461 times
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_player_main_inventory_changed unreliable

Post by Rseding91 »

The event is not instant. it happens at the end of the current tick that the change happened in so if something removes, then adds, then removes, then adds, you still only get 1 event at the end of the tick.
If you want to get ahold of me I'm almost always on Discord.

User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: on_player_main_inventory_changed unreliable

Post by ownlyme »

yeah but in the on_tick function i only check if it happened in the last tick (see my first screenshot)
but it's getting worse:
Screenshot_9.jpg
Screenshot_9.jpg (23.77 KiB) Viewed 1396 times
(this is new....)
when i look at that screenshot i have no clue why my new system works... (99% of the time)

guess my bug is not reproducible..
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_player_main_inventory_changed unreliable

Post by Rseding91 »

Don't use game.print() for debug things that involve same-tick times because you'll hit the spam protection logic and any duplicate messages just get erased.

Always use log() for those kinds of things. I suspect you're just not seeing the duplicate message in the console because it got eaten by spam protection.
If you want to get ahold of me I'm almost always on Discord.

User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: on_player_main_inventory_changed unreliable

Post by ownlyme »

as you see it's written in a way that there won't be any dublicate messages until the first time it detected that the cursor is empty
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_player_main_inventory_changed unreliable

Post by Rseding91 »

Then you'll need to find a way to prove that there's an issue with the game logic. The event uses the same internal item-changed notification system that everything uses and that has *extensive* testing and automated tests in place to verify it's correct.
If you want to get ahold of me I'm almost always on Discord.

User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: on_player_main_inventory_changed unreliable

Post by ownlyme »

i think i got confused because construction robots sometimes go back into your inventory even if there should still be items that they could pick up (but maybe they are reserved?), thus triggering the event.
So i assumed the main_inventory_changed event would always fire even if i have the item in my hand, which it doesn't
But the on_player_cursor_stack_changed event seems to be reliable

sorry for the inconvenience
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

Post Reply

Return to “Not a bug”