[Solved] Turn event.name into actual event name?

Place to get help with not working mods / modding interface.
Post Reply
Kingdud
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Sat Dec 16, 2017 3:23 am
Contact:

[Solved] Turn event.name into actual event name?

Post by Kingdud »

I'm trying to figure out an inter-mod conflict. Part of that is trying to figure out exactly which event is being sent between mods and that it's handled correctly. When I print out event.name, I get '78'. I was hoping for, ya know, an actual name (like script_raised_destroy -- what I expect to find). How can I get the text-version of the event name?
Last edited by Kingdud on Wed Sep 30, 2020 9:11 pm, edited 1 time in total.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Turn event.name into actual event name?

Post by Choumiko »

Code: Select all

local function reverse_event(id)
  for name, event_id in pairs(defines.events) do
    if id == event_id then
      return name
    end
  end
end
game.print(reverse_event(78))
That should do it

Kingdud
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Sat Dec 16, 2017 3:23 am
Contact:

Re: Turn event.name into actual event name?

Post by Kingdud »

Oy vey. Thanks.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [Solved] Turn event.name into actual event name?

Post by eradicator »

For future readers: It's much more efficient to do this as a table lookup:

Code: Select all

local reverse = (function(r) for k,v in pairs(defines.events) do r[v]=k end return r end){}

Code: Select all

game.print(reverse[78])
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”