Unlocking shortcuts by research

Place to get help with not working mods / modding interface.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1759
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Unlocking shortcuts by research

Post by Pi-C »

GCKI used to work with a "car key" item. The recipe for this item would be unlocked when "automobilism" or "cargo-ships" was researched. Now I've changed the prototype of the keys from Prototype/Item to Prototype/Shortcut, and I've got a problem: technology.effects["unlock-recipe"] won't apply anymore, and technology_to_unlock is supposed to be a string value, so the shortcut can be unlocked by one technology only.

I've tried to work around this:

Code: Select all

GCKI.unlock_tech_map = {
  -- Required mod         Technology
  ["base"]              = "automobilism",
  ["cargo-ships"]  = "water_transport",
}

local tech

local unlock = {
  type = "nothing",
  icon = icon,
  icon_size = 64,
  icon_mipmaps = 1,
  effect_description = {"techeffect-description.technology-effect"},
}

for mod_name, tech_name in pairs(GCKI.unlock_tech_map) do
  tech = data.raw.technology[tech_name]
  if mods[mod_name] and tech then
    tech.effects = tech.effects or {}
    table.insert(tech.effects, unlock)
  end
end
However, only "automobilism" (the tech specified in LuaShortcut.technology_to_unlock) will get the effect in the game. Is there really no way to unlock a shortcut by researching any of several techs?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
robot256
Smart Inserter
Smart Inserter
Posts: 1248
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Unlocking shortcuts by research

Post by robot256 »

It's definitely odd that shortcuts put the technology reference in the shortcut prototype rather than the technology unlock list. That could be a mod interface request.

To get around it, I suppose the answer is to put some code in the on_research_completed and related events, to keep the shortcut unlock state consistent with what technologies are researched.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1759
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Unlocking shortcuts by research

Post by Pi-C »

robot256 wrote: Mon Jun 20, 2022 4:29 am It's definitely odd that shortcuts put the technology reference in the shortcut prototype rather than the technology unlock list. That could be a mod interface request.
OK, I'll do that. I'd also be content if technology_to_unlock could be either a string or an array of strings.

To get around it, I suppose the answer is to put some code in the on_research_completed and related events, to keep the shortcut unlock state consistent with what technologies are researched.
I don't know what happened yesterday. I'm pretty sure I didn't see the keys' symbol among the effects of the "water_transport" tech, but there it is:
tech.png
tech.png (57.35 KiB) Viewed 1488 times
Still, having to manually add a "nothing" unlock to techs is not really intuitive. :-)

By the way, I was already listening to on_research_completed and on_research_reversed. This way, I can turn off the event handlers for on_player_*selected_area and on_lua_shortcut when they are not needed (i.e., when no force has researched an unlock tech).
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Modding help”