Need help replacing a recipie

Place to get help with not working mods / modding interface.
User avatar
demongo
Inserter
Inserter
Posts: 25
Joined: Sat Apr 13, 2019 11:09 pm
Contact:

Need help replacing a recipie

Post by demongo »

i have a mod that adds various levels or deepmining, and i want to replace old mining recipes with new researched ones.

script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX1" then
data.raw.recipe."deep-mining-5".enabled = false
end
end)
Last edited by Koub on Mon Nov 23, 2020 10:12 pm, edited 1 time in total.
Reason: Lowered case in subject
Pi-C
Smart Inserter
Smart Inserter
Posts: 1742
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: NEED HELP REPLACING A RECIPIE

Post by Pi-C »

demongo wrote: Mon Nov 23, 2020 9:07 pm i have a mod that adds various levels or deepmining, and i want to replace old mining recipes with new researched ones.

script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX1" then
data.raw.recipe."deep-mining-5".enabled = false
end
end)
Won't work. script.on_event is available in control stage only (once you've started a new game or loaded an existing one), but data.raw.recipe will only exist during the data stage (when Factorio is loading).
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
JonnyOnSeSocks
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue Nov 17, 2020 10:11 pm
Contact:

Re: Need help replacing a recipie

Post by JonnyOnSeSocks »

in the control stage, recipes are unlocked for forces. You can disable the old recipes for the force of the research trigger event.

Code: Select all

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX1" then
         local force = event.research.force
         force.recipes["deep-minig-5"].enabled = false
    end
end) 
User avatar
demongo
Inserter
Inserter
Posts: 25
Joined: Sat Apr 13, 2019 11:09 pm
Contact:

Re: Need help replacing a recipie

Post by demongo »

omg thank you :) if i hit another snag i will ask here... working on an inf tech for my deep mines atm
https://mods.factorio.com/user/demongo1154
User avatar
demongo
Inserter
Inserter
Posts: 25
Joined: Sat Apr 13, 2019 11:09 pm
Contact:

Re: Need help replacing a recipie

Post by demongo »

HMM, it appears it does not like me...
Attachments
ERROR.png
ERROR.png (39.99 KiB) Viewed 2654 times
User avatar
demongo
Inserter
Inserter
Posts: 25
Joined: Sat Apr 13, 2019 11:09 pm
Contact:

Re: Need help replacing a recipie

Post by demongo »

CURRENT WIP: help appreciated...

Code: Select all

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX1" then
         local force = event.research.force
         force.recipes["deep-minig-5"].enabled = false
    end
end)
script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX2" then
         local force = event.research.force
         force.recipes["deep-mining-X1"].enabled = false
    end
end)
script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX3" then
         local force = event.research.force
         force.recipes["deep-mining-X2"].enabled = false
    end
end)
script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX4" then
         local force = event.research.force
         force.recipes["deep-mining-X3"].enabled = false
    end
end)

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX5" then
         local force = event.research.force
         force.recipes["deep-mining-X4"].enabled = false
    end
end)

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX6" then
         local force = event.research.force
         force.recipes["deep-mining-X5"].enabled = false
    end
end)

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX7" then
         local force = event.research.force
         force.recipes["deep-mining-X6"].enabled = false
    end
end)

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX8" then
         local force = event.research.force
         force.recipes["deep-mining-X7"].enabled = false
    end
end)

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX9" then
         local force = event.research.force
         force.recipes["deep-mining-X8"].enabled = false
    end
end)

-- allow productivity for "deep-mining-2"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-2")
  end
end

-- allow productivity for "deep-mining-3"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-3")
  end
end

-- allow productivity for "deep-mining-4"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-4")
  end
end

-- allow productivity for "deep-mining-5"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-5")
  end
end

-- allow productivity for "deep-mining-X1"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x1")
  end
end

-- allow productivity in "deep-mining-X2"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x2")
  end
end

-- allow productivity for "deep-mining-X3"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x3")
  end
end

-- allow productivity for "deep-mining-X4"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x4")
  end
end

-- allow productivity for "deep-mining-X5"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x5")
  end
end

-- allow productivity for "deep-mining-X6"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x6")
  end
end

-- allow productivity for "deep-mining-X7"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x7")
  end
end

-- allow productivity for "deep-mining-X8"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x8")
  end
end

-- allow productivity for "deep-mining-X9"
for k,v in pairs(data.raw.module) do
  if v.limitation then
    table.insert(v.limitation, "deep-mining-x9")
  end
end
[/size]
Xorimuth
Filter Inserter
Filter Inserter
Posts: 708
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Need help replacing a recipie

Post by Xorimuth »

You can't bind multiple times to the same event (defines.events.on_research_finished). Put those all into one block.
Secondly, you are mixing up control and data. The event hooks should go in control.lua and the recipe additions (anything that deals with data.raw) should go in data.lua. That's why you are getting that error - script is not defined in data.lua, only control.lua.
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
User avatar
demongo
Inserter
Inserter
Posts: 25
Joined: Sat Apr 13, 2019 11:09 pm
Contact:

Re: Need help replacing a recipie

Post by demongo »

aw, learning a little more each day im figuring this out... thanks...
Pi-C
Smart Inserter
Smart Inserter
Posts: 1742
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Need help replacing a recipie

Post by Pi-C »

demongo wrote: Tue Dec 01, 2020 5:27 am aw, learning a little more each day im figuring this out... thanks...
Apart from what Xorimuth has explained, there also seems to be a small typo in the first block:

Code: Select all

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == "deep-mine-MKX1" then
         local force = event.research.force
         force.recipes["deep-minig-5"].enabled = false
    end
end)
If there is no recipe "deep-minig-5" ("minig" --> "mining"!), this won't ever work as expected. Also, you should definitely read up on the data life cycle, and having a look at eradicator's tutorial mod may also be helpful. :-)
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”