Is there any way to derive the prototype name (string) from event.name(numeric)?12490.617 Script @__Pi-C_lib__/libs/debugging.lua:185: Yes: raising event minime_exchanged_characters!
12490.617 Script @__Pi-C_lib__/libs/debugging.lua:185:
====================================================================================================
Entered event script for unnamed event
Event data: player_index = 1, old_character = character "character" (517), new_character = character "IRobot_character_skin" (518), old_unit_number = 517, new_unit_number = 518, tick = 297822, mod_name = "minime"
(@__minime__/scripts/events.lua: 297)
====================================================================================================
12490.617 Script @__Pi-C_lib__/libs/debugging.lua:185:
----------------------------------------------------------------------------------------------------
Entered function event_handler({mod_name = "minime", name = 218, new_character = "[LuaEntity: IRobot_character_skin at [gps=6.8,-2.9]]", new_unit_number = 518, old_character = "[LuaEntity: character at [gps=7.0,-2.7]]", old_unit_number = 517, player_index = 1, tick = 297822})
(@__minime__/scripts/events.lua: 256)
----------------------------------------------------------------------------------------------------
[boskid] How to get the ID of a custom-event?
[boskid] How to get the ID of a custom-event?
We can now define custom events as CustomEventPrototype during the data stage. We can also use the name (string) of that prototype with script.raise_event and script.on_event. However, it seems that the name passed on with the event data is numeric:
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: How to get the ID of a custom-event?
Can you post the relevant code?
I assume you're looking at these pages:
https://lua-api.factorio.com/latest/eve ... InputEvent - particularly "selected_prototype"
https://lua-api.factorio.com/latest/pro ... otype.html - which mentions "include_selected_prototype" should be set to true
https://lua-api.factorio.com/latest/con ... eData.html - "derived_type"
I assume you're looking at these pages:
https://lua-api.factorio.com/latest/eve ... InputEvent - particularly "selected_prototype"
https://lua-api.factorio.com/latest/pro ... otype.html - which mentions "include_selected_prototype" should be set to true
https://lua-api.factorio.com/latest/con ... eData.html - "derived_type"
Re: How to get the ID of a custom-event?
Sure. I create the event prototype in data.lua:
Code: Select all
data:extend({
{
type = "custom-event",
name = "minime_exchanged_characters",
}
})
Code: Select all
local pass_on = {
player_index = player.index,
old_character = old_char,
new_character = new_char,
old_unit_number = old_id,
new_unit_number = new_id,
god_mode = data.god_mode,
editor_mode = data.editor_mode
}
script.raise_event("minime_exchanged_characters", pass_on)
Code: Select all
script.on_event("minime_exchanged_characters", function(event) … end)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: [boskid] How to get the ID of a custom-event?
@boskid: Hi! As I've just noticed you've taken an interest in this, there is a related issue with LuaBootstrap::get_event_handler. Currently, passing on the name of a custom event will result in an error:
While we could work around this if we'd get the numeric ID of custom events, it may also be a good idea to allow the string name of a custom event as argument for script.get_event_handler. I hope that I don't come across as too greedy!
Also, could you tell me why LuaBootstrap.generate_event_name is still available? It's a bit confusing to have two techniques to achieve the same thing (define a custom event). My guess is, it's still there for backwards compatibility but may be removed in the future – can you confirm that, or is there another reason?
Code: Select all
11413.654 Error MainLoop.cpp:1432: Exception at tick 286131: Error while running command "minime-show-active-events": Unknown custom-input name: minime_exchanged_characters
stack traceback:
[C]: in function 'get_event_handler'
Also, could you tell me why LuaBootstrap.generate_event_name is still available? It's a bit confusing to have two techniques to achieve the same thing (define a custom event). My guess is, it's still there for backwards compatibility but may be removed in the future – can you confirm that, or is there another reason?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: [boskid] How to get the ID of a custom-event?
I can see some extremely niche uses for wanting to be able to dynamically generate events perhaps? Probably not something that would be worth adding if we'd already had the prototype-based custom events but since it is there already I guess it may as well stay.Pi-C wrote: ↑Fri Nov 29, 2024 2:15 pm Also, could you tell me why LuaBootstrap.generate_event_name is still available? It's a bit confusing to have two techniques to achieve the same thing (define a custom event). My guess is, it's still there for backwards compatibility but may be removed in the future – can you confirm that, or is there another reason?
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Re: [boskid] How to get the ID of a custom-event?
It is still useful for custom scenariosPi-C wrote: ↑Fri Nov 29, 2024 2:15 pm Also, could you tell me why LuaBootstrap.generate_event_name is still available? It's a bit confusing to have two techniques to achieve the same thing (define a custom event). My guess is, it's still there for backwards compatibility but may be removed in the future – can you confirm that, or is there another reason?
Re: [boskid] How to get the ID of a custom-event?
Yes, makes sense. But that means we'd still have to keep two methods for registering custom events: the easy way by checking prototypes.custom_events, and by asking the other mods for the event ID per remote call. This could be circumvented if we could pass on a string (the name of the custom-event) and there was a map from event names to numeric IDs (similar to defines.events, but dynamic). Needless to say, I'm not sure whether this even could be implemented …
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!