quick question with control.lua

Place to get help with not working mods / modding interface.
Post Reply
npuldon
Fast Inserter
Fast Inserter
Posts: 159
Joined: Thu Dec 08, 2016 8:36 am
Contact:

quick question with control.lua

Post by npuldon »

Hello all!

I have a quick question on setting up a control.lua file. I'd like to enable several specific techs from the start of the game. What is the syntax for in a control.lua file so I do not need to use in-game /c scripts for each tech/game?

Example techs (from console commands wiki):
/c game.player.force.technologies['electric-energy-distribution-1'].researched=true
/c game.player.force.technologies['steel-processing'].researched=true

I have this example from arumba's accelerated start mod but I haven't had luck in using the above commands in the file to any success:

~~~~~~~~~~~~~~~~~~~~
script.on_event(defines.events.on_player_created, function(event)
game.players[event.player_index].color = {r = 0, g = 0, b = 1, a = .7}; -- change player color to blue
local player = game.players[event.player_index]
local inventory = player.get_inventory(defines.inventory.player_quickbar)
inventory.clear()
inventory.set_filter(1,"transport-belt")
inventory.set_filter(2,"inserter")

-- materials
player.insert{name="steel-axe", count=20}
.....
end)
~~~~~~~~~~~~~~~~~~~~~

Thank you so much for your help!

daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: quick question with control.lua

Post by daniel34 »

Using the above code (local player = game.players[event.player_index]) you already have a shortcut to the player entity itself, so the code should be

Code: Select all

player.force.technologies['electric-energy-distribution-1'].researched=true
player.force.technologies['steel-processing'].researched=true
quick links: log file | graphical issues | wiki

npuldon
Fast Inserter
Fast Inserter
Posts: 159
Joined: Thu Dec 08, 2016 8:36 am
Contact:

Re: quick question with control.lua

Post by npuldon »

Thank you kindly! that worked great. I was place the code one line to high up in the file.

Cheers

Post Reply

Return to “Modding help”