console command question

Post all other topics which do not belong to any other category.
john
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Mar 11, 2016 1:22 am
Contact:

console command question

Post 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!
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3718
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: console command question

Post 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

Code: Select all

/c print("Hello world!")
Note that everything will be lost when you reload the game, unless you make it into a mod.
john
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Mar 11, 2016 1:22 am
Contact:

Re: console command question

Post 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 ?
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5290
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: console command question

Post 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
kovarex
Factorio Staff
Factorio Staff
Posts: 8207
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: console command question

Post 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.
Post Reply

Return to “General discussion”