Allow on_pre events to return false and abort the event
Allow on_pre events to return false and abort the event
I would like to be able to return false (or some other sentinel value) from my event handler for on_pre_* events and cause the rest of the event to not happen. This would work like browser javascript event handlers that disable the default functionality for the event that is being triggered.
- Ranakastrasz
- Smart Inserter
- Posts: 2173
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: Allow on_pre events to return false and abort the event
On that thought, I would like to be able to have you change any of the arguments the event handler holds, and have it use those instead.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: Allow on_pre events to return false and abort the event
Factorio events don't support this concept. In fact the game itself doesn't support this concept.
So, this isn't likely to ever happen.
So, this isn't likely to ever happen.
If you want to get ahold of me I'm almost always on Discord.
-
- Inserter
- Posts: 47
- Joined: Fri Mar 17, 2017 9:19 pm
- Contact:
Re: Allow on_pre events to return false and abort the event
When trying to build a new entity in a location that is not valid, like a furnace on top of belts, the game stops the player from building the object. I don't know if this concept really applies to on_pre or on_put_item events. However something like on_validate_entity_placement event where placement could be denied before the game starts the on_put_item -> on_built_entity event chain would be very useful for scenarios I'm currently working on.
I work around this right now by deleting the entity in on_built_entity and refunding the item to the player's inventory, which is not really intuitive.
Re: Allow on_pre events to return false and abort the event
In case you didn't know, you can cancel an item placement by doing player.clean_cursor() in on_put_item (before on_built_entity gets raised). Of course the player won't have the item in hand anymore after this. Similarly, you can change what is being placed by changing the player's cursor_stack in on_put_item.
Factorio Mod Portal Notifier - https://fac-notify.ml/
Cut and paste tools - https://mods.factorio.com/mods/mickael9/cut-and-paste
Portable Chests - https://mods.factorio.com/mods/mickael9/portable-chests
Cut and paste tools - https://mods.factorio.com/mods/mickael9/cut-and-paste
Portable Chests - https://mods.factorio.com/mods/mickael9/portable-chests
Re: Allow on_pre events to return false and abort the event
What happens if the player has no inventory space available?mickael9 wrote:In case you didn't know, you can cancel an item placement by doing player.clean_cursor() in on_put_item (before on_built_entity gets raised). Of course the player won't have the item in hand anymore after this. Similarly, you can change what is being placed by changing the player's cursor_stack in on_put_item.
Re: Allow on_pre events to return false and abort the event
Either drop the item on ground or put it back to the cursor in the next tick and hopefully no one will notice?doc wrote:What happens if the player has no inventory space available?mickael9 wrote:In case you didn't know, you can cancel an item placement by doing player.clean_cursor() in on_put_item (before on_built_entity gets raised). Of course the player won't have the item in hand anymore after this. Similarly, you can change what is being placed by changing the player's cursor_stack in on_put_item.
Re: Allow on_pre events to return false and abort the event
You can place and remove on the same tick, but you can get dust of placing.Mooncat wrote:Either drop the item on ground or put it back to the cursor in the next tick and hopefully no one will notice?