Cant access technologies in control.lua[Solved]

Place to get help with not working mods / modding interface.
User avatar
Kabaril
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Jul 29, 2017 10:24 pm
Contact:

Cant access technologies in control.lua[Solved]

Post by Kabaril »

I just wanted to print out all technologies into a file, but for some reason it doesnt show a single one:

Control.lua

Code: Select all

require("libs/logger")

local function GetTech()
LOGGER = Logger.new("datascan", "technology", false)
LOGGER.log("Start")
local dummyforce = game.create_force("dummy")
dummyforce.enable_research()
dummyforce.research_all_technologies(false)
dummyforce.reset()
for _, tech in pairs(dummyforce.technologies) do 
LOGGER.log("Name\n")
LOGGER.log(tech.name)
LOGGER.log("\n")
end
end

local function onInit()
	GetTech()
end

script.on_init(onInit)
This is using the factorio stdlib logger, but it only prints "Start"
Last edited by Kabaril on Wed Aug 29, 2018 7:53 pm, edited 1 time in total.
orzelek
Smart Inserter
Smart Inserter
Posts: 3923
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Cant access technologies in control.lua

Post by orzelek »

Don't call LuaForce.reset() because it does what name implies - it will reset researched techs.

Also there is a dictonary technology_prototypes that might give you all the info without need to create a force.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14264
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Cant access technologies in control.lua

Post by Rseding91 »

Why are you using a library to do logging when you can just do: log("your contents here") ?
If you want to get ahold of me I'm almost always on Discord.
User avatar
Kabaril
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Jul 29, 2017 10:24 pm
Contact:

Re: Cant access technologies in control.lua

Post by Kabaril »

orzelek wrote:Don't call LuaForce.reset() because it does what name implies - it will reset researched techs.

Also there is a dictonary technology_prototypes that might give you all the info without need to create a force.
Thanks! My problem is solved now
User avatar
Kabaril
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Jul 29, 2017 10:24 pm
Contact:

Re: Cant access technologies in control.lua

Post by Kabaril »

Rseding91 wrote:Why are you using a library to do logging when you can just do: log("your contents here") ?
Thanks! The problem was actually the logger, which for some reason only printed one line.

The only reason i used it was to get all of the log into a separate file, but im not sure if that is possible
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Cant access technologies in control.lua

Post by Nexela »

Kabaril wrote:
Rseding91 wrote:Why are you using a library to do logging when you can just do: log("your contents here") ?
Thanks! The problem was actually the logger, which for some reason only printed one line.

The only reason i used it was to get all of the log into a separate file, but im not sure if that is possible
The default setting for the logger is to only write the log after xxx ticks, however it needs to be triggered after xxx ticks to flush. I havn't looked at the code recently but I think doing a LOGGER.write() should dump it right away.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Cant access technologies in control.lua

Post by darkfrei »

Kabaril wrote:I just wanted to print out all technologies into a file, but for some reason it doesnt show a single one:
Console#Write_all_researched_technologies_to_file

Code: Select all

/c local list = {}
for _, tech in pairs(game.player.force.technologies) do 
	if tech.researched then
    list[#list+1] = tech.name
  end
end
game.write_file("techs.lua", serpent.block(list) .. "\n", true)
User avatar
Kabaril
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Jul 29, 2017 10:24 pm
Contact:

Re: Cant access technologies in control.lua

Post by Kabaril »

Thanks to everyone, It works now.
Post Reply

Return to “Modding help”