Allow on_pre events to return false and abort the event

Things that we aren't going to implement
sparr
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Allow on_pre events to return false and abort the event

Post by sparr »

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.
User avatar
Ranakastrasz
Smart Inserter
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

Post by Ranakastrasz »

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
Rseding91
Factorio Staff
Factorio Staff
Posts: 14598
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Allow on_pre events to return false and abort the event

Post by Rseding91 »

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.
If you want to get ahold of me I'm almost always on Discord.
SilverB1rd
Inserter
Inserter
Posts: 47
Joined: Fri Mar 17, 2017 9:19 pm
Contact:

Re: Allow on_pre events to return false and abort the event

Post by SilverB1rd »

Image

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.
User avatar
mickael9
Fast Inserter
Fast Inserter
Posts: 112
Joined: Mon Mar 14, 2016 4:04 am
Contact:

Re: Allow on_pre events to return false and abort the event

Post by mickael9 »

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.
doc
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Mon Mar 28, 2016 3:52 pm
Contact:

Re: Allow on_pre events to return false and abort the event

Post by doc »

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.
What happens if the player has no inventory space available?
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Allow on_pre events to return false and abort the event

Post by Mooncat »

doc wrote:
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.
What happens if the player has no inventory space available?
Either drop the item on ground or put it back to the cursor in the next tick and hopefully no one will notice?
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Allow on_pre events to return false and abort the event

Post by darkfrei »

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?
You can place and remove on the same tick, but you can get dust of placing.
Post Reply

Return to “Won't implement”