[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: 197
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?
The_LORD_thy_GOD
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sun Nov 10, 2024 5:23 pm
Contact:

Re: [2.0.77] Silent discard of script.raise_event

Post by The_LORD_thy_GOD »

I agree that this behavior is bad and should be addressed in some way. Personally I think it should just allow invalid objects to pass with the understanding that mods receiving mod-generated custom events must validate payloads.

That being said, there is a workaround possible in current API: I have my custom events that need a large payload just send an integer ID, which the receiving mod can then use to retrieve the payload via a remote interface -- this side-steps the problem.
Post Reply

Return to “Modding interface requests”