Page 1 of 1

[Solved] Looking for dictionary eventID -> eventName

Posted: Sun May 10, 2020 5:41 pm
by Impatient
How can I get the actual name of an event? The event data gives me the id, fine, but I want a name.

Code: Select all

defines.events
has a named variable for each id, great. But I need it the other way around. A dictionary where the id is the key and the value is the name

Code: Select all

defines.events[1] = "on_tick"
Is this somewhere available in core or base? Or do I really need to make it myself? :shock:

Re: Looking for dictionary eventID -> eventName

Posted: Sun May 10, 2020 6:17 pm
by Impatient
After using my regex skillz to turn the contents of https://lua-api.factorio.com/latest/def ... nes.events into a table, I found out, that the order, the events are listed there, does not correspond to their ids. :roll:

Re: Looking for dictionary eventID -> eventName

Posted: Sun May 10, 2020 6:24 pm
by posila
Use your lua skill instead.

Code: Select all

local mapping = {}
for name, id in pairs(defines.events) do
  mapping[id] = name
end

Re: Looking for dictionary eventID -> eventName

Posted: Sun May 10, 2020 6:44 pm
by Impatient
My final solution was to use

Code: Select all

serpent.block(defines.events)
to get the contents of that table printed.
Then I used regex (in Notepad++)

Code: Select all

([^ ]+) ([=]{1}) ([\d]+)

replaced by

eventNames[\3] = "\1"
to turn it in a dictionary definition.

This is the result, in case anyone ever has the same need (taken from version 0.18.22):

Code: Select all

  eventNames[113] = "on_ai_command_completed",
  eventNames[118] = "on_area_cloned",
  eventNames[55] = "on_biter_base_built",
  eventNames[119] = "on_brush_cloned",
  eventNames[136] = "on_build_base_arrived",
  eventNames[6] = "on_built_entity",
  eventNames[21] = "on_cancelled_deconstruction",
  eventNames[115] = "on_cancelled_upgrade",
  eventNames[90] = "on_character_corpse_expired",
  eventNames[138] = "on_chart_tag_added",
  eventNames[139] = "on_chart_tag_modified",
  eventNames[140] = "on_chart_tag_removed",
  eventNames[98] = "on_chunk_charted",
  eventNames[106] = "on_chunk_deleted",
  eventNames[12] = "on_chunk_generated",
  eventNames[80] = "on_combat_robot_expired",
  eventNames[71] = "on_console_chat",
  eventNames[72] = "on_console_command",
  eventNames[33] = "on_cutscene_waypoint_reached",
  eventNames[60] = "on_difficulty_settings_changed",
  eventNames[117] = "on_entity_cloned",
  eventNames[97] = "on_entity_damaged",
  eventNames[4] = "on_entity_died",
  eventNames[57] = "on_entity_renamed",
  eventNames[31] = "on_entity_settings_pasted",
  eventNames[130] = "on_entity_spawned",
  eventNames[146] = "on_force_cease_fire_changed",
  eventNames[27] = "on_force_created",
  eventNames[145] = "on_force_friends_changed",
  eventNames[101] = "on_forces_merged",
  eventNames[28] = "on_forces_merging",
  eventNames[120] = "on_game_created_from_scenario",
  eventNames[3] = "on_gui_checked_state_changed",
  eventNames[1] = "on_gui_click",
  eventNames[84] = "on_gui_closed",
  eventNames[141] = "on_gui_confirmed",
  eventNames[67] = "on_gui_elem_changed",
  eventNames[142] = "on_gui_location_changed",
  eventNames[83] = "on_gui_opened",
  eventNames[143] = "on_gui_selected_tab_changed",
  eventNames[58] = "on_gui_selection_state_changed",
  eventNames[144] = "on_gui_switch_state_changed",
  eventNames[2] = "on_gui_text_changed",
  eventNames[85] = "on_gui_value_changed",
  eventNames[100] = "on_land_mine_armed",
  eventNames[34] = "on_lua_shortcut",
  eventNames[20] = "on_marked_for_deconstruction",
  eventNames[114] = "on_marked_for_upgrade",
  eventNames[53] = "on_market_item_purchased",
  eventNames[82] = "on_mod_item_opened",
  eventNames[5] = "on_picked_up_item",
  eventNames[50] = "on_player_alt_selected_area",
  eventNames[36] = "on_player_ammo_inventory_changed",
  eventNames[35] = "on_player_armor_inventory_changed",
  eventNames[108] = "on_player_banned",
  eventNames[45] = "on_player_built_tile",
  eventNames[96] = "on_player_cancelled_crafting",
  eventNames[56] = "on_player_changed_force",
  eventNames[81] = "on_player_changed_position",
  eventNames[51] = "on_player_changed_surface",
  eventNames[89] = "on_player_cheat_mode_disabled",
  eventNames[88] = "on_player_cheat_mode_enabled",
  eventNames[70] = "on_player_configured_blueprint",
  eventNames[13] = "on_player_crafted_item",
  eventNames[24] = "on_player_created",
  eventNames[29] = "on_player_cursor_stack_changed",
  eventNames[69] = "on_player_deconstructed_area",
  eventNames[76] = "on_player_demoted",
  eventNames[41] = "on_player_died",
  eventNames[93] = "on_player_display_resolution_changed",
  eventNames[94] = "on_player_display_scale_changed",
  eventNames[26] = "on_player_driving_changed_state",
  eventNames[54] = "on_player_dropped_item",
  eventNames[125] = "on_player_fast_transferred",
  eventNames[37] = "on_player_gun_inventory_changed",
  eventNames[43] = "on_player_joined_game",
  eventNames[109] = "on_player_kicked",
  eventNames[44] = "on_player_left_game",
  eventNames[32] = "on_player_main_inventory_changed",
  eventNames[65] = "on_player_mined_entity",
  eventNames[8] = "on_player_mined_item",
  eventNames[46] = "on_player_mined_tile",
  eventNames[86] = "on_player_muted",
  eventNames[92] = "on_player_pipette",
  eventNames[38] = "on_player_placed_equipment",
  eventNames[75] = "on_player_promoted",
  eventNames[73] = "on_player_removed",
  eventNames[39] = "on_player_removed_equipment",
  eventNames[124] = "on_player_repaired_entity",
  eventNames[42] = "on_player_respawned",
  eventNames[19] = "on_player_rotated_entity",
  eventNames[49] = "on_player_selected_area",
  eventNames[149] = "on_player_set_quick_bar_slot",
  eventNames[68] = "on_player_setup_blueprint",
  eventNames[123] = "on_player_toggled_alt_mode",
  eventNames[116] = "on_player_toggled_map_editor",
  eventNames[102] = "on_player_trash_inventory_changed",
  eventNames[110] = "on_player_unbanned",
  eventNames[87] = "on_player_unmuted",
  eventNames[74] = "on_player_used_capsule",
  eventNames[129] = "on_post_entity_died",
  eventNames[126] = "on_pre_chunk_deleted",
  eventNames[30] = "on_pre_entity_settings_pasted",
  eventNames[91] = "on_pre_ghost_deconstructed",
  eventNames[95] = "on_pre_player_crafted_item",
  eventNames[40] = "on_pre_player_died",
  eventNames[103] = "on_pre_player_left_game",
  eventNames[11] = "on_pre_player_mined_item",
  eventNames[131] = "on_pre_player_removed",
  eventNames[150] = "on_pre_player_toggled_map_editor",
  eventNames[127] = "on_pre_robot_exploded_cliff",
  eventNames[151] = "on_pre_script_inventory_resized",
  eventNames[105] = "on_pre_surface_cleared",
  eventNames[63] = "on_pre_surface_deleted",
  eventNames[9] = "on_put_item",
  eventNames[18] = "on_research_finished",
  eventNames[17] = "on_research_started",
  eventNames[25] = "on_resource_depleted",
  eventNames[14] = "on_robot_built_entity",
  eventNames[47] = "on_robot_built_tile",
  eventNames[128] = "on_robot_exploded_cliff",
  eventNames[16] = "on_robot_mined",
  eventNames[64] = "on_robot_mined_entity",
  eventNames[48] = "on_robot_mined_tile",
  eventNames[15] = "on_robot_pre_mined",
  eventNames[111] = "on_rocket_launch_ordered",
  eventNames[10] = "on_rocket_launched",
  eventNames[59] = "on_runtime_mod_setting_changed",
  eventNames[152] = "on_script_inventory_resized",
  eventNames[112] = "on_script_path_request_finished",
  eventNames[148] = "on_script_trigger_effect",
  eventNames[7] = "on_sector_scanned",
  eventNames[52] = "on_selected_entity_changed",
  eventNames[147] = "on_string_translated",
  eventNames[104] = "on_surface_cleared",
  eventNames[61] = "on_surface_created",
  eventNames[62] = "on_surface_deleted",
  eventNames[121] = "on_surface_imported",
  eventNames[122] = "on_surface_renamed",
  eventNames[99] = "on_technology_effects_reset",
  eventNames[0] = "on_tick",
  eventNames[23] = "on_train_changed_state",
  eventNames[66] = "on_train_created",
  eventNames[107] = "on_train_schedule_changed",
  eventNames[22] = "on_trigger_created_entity",
  eventNames[137] = "on_trigger_fired_artillery",
  eventNames[133] = "on_unit_added_to_group",
  eventNames[132] = "on_unit_group_created",
  eventNames[135] = "on_unit_group_finished_gathering",
  eventNames[134] = "on_unit_removed_from_group",
  eventNames[77] = "script_raised_built",
  eventNames[78] = "script_raised_destroy",
  eventNames[79] = "script_raised_revive"

Re: Looking for dictionary eventID -> eventName

Posted: Sun May 10, 2020 6:47 pm
by Impatient
posila wrote: Sun May 10, 2020 6:24 pm Use your lua skill instead.

Code: Select all

local mapping = {}
for name, id in pairs(defines.events) do
  mapping[id] = name
end
thanks

edit: This is of course the way to do it. I still don't get used to lua. If "defines.events" is a table, then "defines.events.on_tick" is not a variable but it is a string key.

Re: Looking for dictionary eventID -> eventName

Posted: Mon May 11, 2020 12:49 pm
by darkfrei
Impatient wrote: Sun May 10, 2020 6:47 pm edit: This is of course the way to do it. I still don't get used to lua. If "defines.events" is a table, then "defines.events.on_tick" is not a variable but it is a string key.
I have nice tool to write it as string, but I am not sure that it works:

Code: Select all

defines.events.on_tick = {defines.events.on_tick = 0}