Baffled by inserting equipment

Place to get help with not working mods / modding interface.
Post Reply
Strategic Sage
Inserter
Inserter
Posts: 35
Joined: Tue Jan 24, 2017 11:52 pm
Contact:

Baffled by inserting equipment

Post by Strategic Sage »

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:

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)
** 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:

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)
** 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.

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

Re: Baffled by inserting equipment

Post by daniel34 »

I made an empty mod and copied your control.lua code over, but the game complains at require "defines" because there is no defines.lua found. It does this because defines and util are both built-in and you don't have to require them.

Removing both these lines and starting a new game it actually does what your code says, it gives me a shotgun.
factorio-shotgun.png
factorio-shotgun.png (72.78 KiB) Viewed 2108 times
Make sure you're running on 0.14.21 and remove the requires, then it should work. Or maybe it's just that you missed the shotgun because it's automatically placed into the gun slot instead of the inventory/toolbar.
quick links: log file | graphical issues | wiki

Strategic Sage
Inserter
Inserter
Posts: 35
Joined: Tue Jan 24, 2017 11:52 pm
Contact:

Re: Baffled by inserting equipment

Post by Strategic Sage »

Thanks for the help. I'm 99.9% certain it wasn't adding the shotgun, and I find it curious that I didn't get any errors from having the defines line in there. From my forum searches a lot of the stuff I found is I'm sure old, superceded info and this appears to be another case; a tutorial I was relying on said that both of those require lines were needed to access the relevant libraries.

Regardless, it works now, the assist is much appreciated!

Zentriffic
Burner Inserter
Burner Inserter
Posts: 14
Joined: Thu Jan 12, 2017 2:07 am
Contact:

Re: Baffled by inserting equipment

Post by Zentriffic »

The mods "mini basic start" and Arumba_Accelerated_Start are good examples of how to do this as well.

Articulating
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Oct 17, 2016 10:33 am
Contact:

Re: Baffled by inserting equipment

Post by Articulating »

daniel34 wrote:It does this because defines and util are both built-in and you don't have to require them.
You do have to require util if you want to use it.

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

Re: Baffled by inserting equipment

Post by daniel34 »

Articulating wrote:
daniel34 wrote:It does this because defines and util are both built-in and you don't have to require them.
You do have to require util if you want to use it.
You are right, my fault. I got confused because defines is not required anymore and util is automatically included in the data.lua phase by the base game. But you're correct, if you want to use util in a control.lua script (mod or scenario) then you'll need to require it.
quick links: log file | graphical issues | wiki

Post Reply

Return to “Modding help”