Page 1 of 1

Cant access technologies in control.lua[Solved]

Posted: Mon Aug 27, 2018 4:16 pm
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"

Re: Cant access technologies in control.lua

Posted: Tue Aug 28, 2018 10:17 am
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.

Re: Cant access technologies in control.lua

Posted: Tue Aug 28, 2018 11:09 pm
by Rseding91
Why are you using a library to do logging when you can just do: log("your contents here") ?

Re: Cant access technologies in control.lua

Posted: Wed Aug 29, 2018 12:31 am
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

Re: Cant access technologies in control.lua

Posted: Wed Aug 29, 2018 12:33 am
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

Re: Cant access technologies in control.lua

Posted: Wed Aug 29, 2018 3:44 am
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.

Re: Cant access technologies in control.lua

Posted: Wed Aug 29, 2018 10:49 am
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)

Re: Cant access technologies in control.lua

Posted: Wed Aug 29, 2018 7:53 pm
by Kabaril
Thanks to everyone, It works now.