Baffled by inserting equipment
Posted: Wed Jan 25, 2017 2:37 pm
I've been following Factorio for a while now, and it's the first game in a long time that has made me want to put the work into modding. I know enough to be dangerous in VB and C++, so I'm not a stranger to coding, but this is my first crack at Lua. Having said that, I've gotten a bit aggravated and completely confused in trying to get some things to work. I'm just testing out stuff to try and figure out how to do things at the moment.
Here's my current control.lua for the mod I've started:
** The first part of this works; toolbelt technology starts researched. That tells me that I've got the right file structure, haven't corrupted control.lua in some way or saved it as the wrong file type, messed up with the wrong file editor, etc.
** No matter what I do, the second part will not work. There's more I want to do with it in terms of adding and removing equipment at startup, but again this is just a test to make sure things are working(small changes before big, etc.). I based this on the included control.lua that Factorio comes with for the freeplay scenario. That starts off like this:
** The function definition, event, etc. are exactly the same here! I've even copy-pasted one over the other to be certain. If I put the line of code to add the shotgun in this function, it works. Put any of this stuff in my mod's directory and the control.lua there, the game ignores it. It doesn't give me an error message -- it just doesn't do anything.
What am I missing here? Thanks in advance.
Here's my current control.lua for the mod I've started:
Code: Select all
require "util"
require "defines"
script.on_init(function()
local force = game.forces.player
force.technologies['toolbelt'].researched=true
end)
script.on_event(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
player.insert{name="shotgun", count=1}
end)
** No matter what I do, the second part will not work. There's more I want to do with it in terms of adding and removing equipment at startup, but again this is just a test to make sure things are working(small changes before big, etc.). I based this on the included control.lua that Factorio comes with for the freeplay scenario. That starts off like this:
Code: Select all
script.on_event(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
player.insert{name="iron-plate", count=8}
player.insert{name="pistol", count=1}
player.insert{name="firearm-magazine", count=10}
player.insert{name="burner-mining-drill", count = 1}
player.insert{name="stone-furnace", count = 1}
player.force.chart(player.surface, {{player.position.x - 200, player.position.y - 200}, {player.position.x + 200, player.position.y + 200}})
if (#game.players <= 1) then
game.show_message_dialog{text = {"msg-intro"}}
else
player.print({"msg-intro"})
end
end)
What am I missing here? Thanks in advance.