[Scripting Assistance] Trying to set dynamically generated techs to unlocked by default

Place to get help with not working mods / modding interface.
DwarfTech
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sat Mar 23, 2019 2:43 pm
Contact:

[Scripting Assistance] Trying to set dynamically generated techs to unlocked by default

Post by DwarfTech »

Hello once again. Since my last post and all the help I've gotten there, I've started on a new project which is going well so far. It's going to be an addon for Beekeeping 2 which enables all bee techs from the beginning, and adjusts recipes such that it can be used to start up in a seablock-style/no resource world. All's been well until I started looking at the dynamically created ore bee techs, which all have a prefixed beekeeping name, with the species name added on based on the ores present in a given game. I.E. bee-technology-[Ore Name] I'm not sure how to reference those techs in the unlock function. What I have so far:

Code: Select all

local function main(e)
 if game.active_mods["NPBees2"] then
	for _, force in pairs(game.forces) do
		if settings.startup["Starting-Bees"] and settings.startup["Starting-Bees"].value == true then
			force.technologies["beekeeping-1"].researched = true
			force.technologies["beekeeping-2"].researched = true
			force.technologies["bee-technology-"].researched = true <-- This is the part causing nil errors on world start/load
		end
	end
end
end

local function player_created(e)
	main(e)
end

local function cutscene_cancelled(e)
  if remote.interfaces["freeplay"] then
    main(e)
  end
end

script.on_event(defines.events.on_player_created,player_created)
script.on_event(defines.events.on_cutscene_cancelled,cutscene_cancelled)
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [Scripting Assistance] Trying to set dynamically generated techs to unlocked by default

Post by DaveMcW »

Code: Select all

for _, technology in pairs(force.technologies) do 
  if technology.name:sub(1, 15) == "bee-technology-" then
    technology.researched = true
  end
end
DwarfTech
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sat Mar 23, 2019 2:43 pm
Contact:

Re: [Scripting Assistance] Trying to set dynamically generated techs to unlocked by default

Post by DwarfTech »

Thanks a bunch! Works spectacularly.
Post Reply

Return to “Modding help”