Page 1 of 1
					
				console command question
				Posted: Fri Mar 18, 2016 8:28 am
				by john
				Hello factorio forum users and staff. I was wondering if i could write "batch files" to use console commands but i wasn't able to find much information on the subject in my searches so if you know of any threads explaining it that would be very helpful.   Thanks in advance!
			 
			
					
				Re: console command question
				Posted: Fri Mar 18, 2016 8:37 am
				by DaveMcW
				Yes, you can copy/paste an entire lua file into the console.
You can also define functions that do a bunch of stuff at once.
Code: Select all
/c print = function(text)
  game.local_player.print(text)
end
Note that everything will be lost when you reload the game, unless you make it into a mod.
 
			
					
				Re: console command question
				Posted: Fri Mar 18, 2016 9:36 am
				by john
				Thanks for your response!
DaveMcW wrote:
Note that everything will be lost when you reload the game, unless you make it into a mod.
Funny you should say that because i created this task for myself after this 
viewtopic.php?f=94&t=13863 had an error.
DaveMcW wrote:
Yes, you can copy/paste an entire lua file into the console. 
mind explaining that a bit more? do you mean copy/pasting the contents of a file in game or can i make a lua file and drop it somewhere in the factorio files and activate everything it contains with one command ?
 
			
					
				Re: console command question
				Posted: Fri Mar 18, 2016 11:27 am
				by Klonan
				john wrote:
DaveMcW wrote:
Yes, you can copy/paste an entire lua file into the console. 
mind explaining that a bit more? do you mean copy/pasting the contents of a file in game or can i make a lua file and drop it somewhere in the factorio files and activate everything it contains with one command ?
 
You can copy paste any lua script code into the game console and it will run it,
This includes any event hooks and functions
so for instance you can start a game, and paste the following into console
Code: Select all
/c function give_coin()
  if game.tick % 1500 == 0 then 
    game.players[1].insert{name = "coin", count =  1} 
  end
end
script.on_event(defines.events.on_tick, give_coin)
and it will run the same as if you had this in the control.lua of your mod/scenario
 
			
					
				Re: console command question
				Posted: Fri Mar 18, 2016 12:09 pm
				by kovarex
				Klonan wrote:john wrote:
DaveMcW wrote:
Yes, you can copy/paste an entire lua file into the console. 
mind explaining that a bit more? do you mean copy/pasting the contents of a file in game or can i make a lua file and drop it somewhere in the factorio files and activate everything it contains with one command ?
 
You can copy paste any lua script code into the game console and it will run it,
This includes any event hooks and functions
so for instance you can start a game, and paste the following into console
Code: Select all
/c function give_coin()
  if game.tick % 1500 == 0 then 
    game.players[1].insert{name = "coin", count =  1} 
  end
end
script.on_event(defines.events.on_tick, give_coin)
and it will run the same as if you had this in the control.lua of your mod/scenario
 
Unless you are using replay or playing multiplayer, or save and load the game, as it will break.