[2.0.77] Silent discard of script.raise_event

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 196
Joined: Tue Feb 06, 2024 5:18 am
Contact:

[2.0.77] Silent discard of script.raise_event

Post by hgschmie »

The docs for LuaBootstrap::raise_event clearly state for the data: "Table with extra data that will be passed to the event handler. Any invalid LuaObjects will silently stop the event from being raised."

This is understandable but I wish we could get some sort of feedback. Would it be possible for raise_event to return a boolean indicating success or failure? Given that currently it returns nothing (nil), maybe return "true" if the call failed and false if it succeeded (that would make it possible to write if script_raise_event(...) then ... error managing code ... end for any version.

I have a few events that I raise that have big payloads. The can (in somewhat rare cases) relate to invalid objects. Currently I have the choice of my events not firing in that case or always doing expensive payload sanitation which I almost never need. With a return code, I could replace this:

Code: Select all

    local data = generate_playload()
    sanitize_payload_in_an expensive_way(data)
    script.raise_event(my_event, data)
with

Code: Select all

    local data = generate_playload()
    if script.raise_event(my_event, data) then
        sanitize_payload_in_an expensive_way(data)
        assert (not script.raise_event(my_event, data))
    end
Any chance we could something like that? Maybe for 2.1?
Post Reply

Return to “Modding interface requests”