Enable/unhide technology with an event?
Posted: Fri Apr 26, 2024 8:20 am
I'm hoping this is a dumb question, but can you change the enabled/hidden property of a technology with an event?
I thought it would be data.raw.technology["hidden-technology"].hidden = false (similar for enabled), but that's not working.
Can this be done?
I realise that this specific scenario could be achieved by making technologies upgrades (although admittedly I'm having trouble getting that to work too), but I'd like to do it this way if I can, because the "available-technology" event does extra stuff in-world, which takes some time and if the player completes the new research before the "otherFunctionThatTakesTime()" finishes, then it breaks.
I thought it would be data.raw.technology["hidden-technology"].hidden = false (similar for enabled), but that's not working.
Can this be done?
Code: Select all
data:extend(
{
{
type = "technology",
name = "available-technology",
icon_size = 256, icon_mipmaps = 4,
icons = "__myMod__/graphics/technology/available-technology.png"
unit =
{
count = 1,
ingredients = {{"automation-science-pack", 1}},
time = 1
},
order = "a"
},
{
type = "technology",
name = "hidden-technology",
icon_size = 256, icon_mipmaps = 4,
icons = "__myMod__/graphics/technology/hidden-technology.png"
prerequisites = {"available-technology"},
unit =
{
count = 1,
ingredients = {{"automation-science-pack", 1}},
time = 1
},
order = "a"
}
})
Code: Select all
script.on_event(defines.events.on_research_finished, function(event)
local researchFinished = {
["available-technology"] = function()
otherFunctionThatTakesTime()
data.raw.technology["hidden-technology"].hidden = false
data.raw.technology["hidden-technology"].enabled = true
end
}
if researchFinished[event.research.name] then
researchFinished[event.research.name]()
end
end)