run a lua file from console

Place to get help with not working mods / modding interface.
Post Reply
Pin-Lui
Inserter
Inserter
Posts: 27
Joined: Fri Apr 01, 2016 12:09 pm
Contact:

run a lua file from console

Post by Pin-Lui »

Hi, i have a question, is it possible to run a lua file with commands from the console? i have a lua file with these line:

Code: Select all

/c game.local_player.insert{name="iron-plate", count=100}; game.local_player.insert{name="coal", count=100}
the commands are just for testing. the Lua file is called test.lua. My question is now, how can i run the lua script from the ingame console? like "run test.lua" and then the game works through the commands in the script. I hope this is possible and not only via events.
Last edited by Pin-Lui on Sat Apr 02, 2016 12:59 pm, edited 1 time in total.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: run a lua file from console

Post by ratchetfreak »

copy the file and paste it in the command line

you don't need the second "/c" though a single paste action is a single command.

Pin-Lui
Inserter
Inserter
Posts: 27
Joined: Fri Apr 01, 2016 12:09 pm
Contact:

Re: run a lua file from console

Post by Pin-Lui »

thx for your reply,
so not possible to group them in a single file and run the file? did you mean open the file ctrl+a ctrl+c console---> ctrl+v and enter? i do it like this.

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: run a lua file from console

Post by Adil »

Well, you could wrap them in events or interface commands inside a mod, but there's no trivial solution.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

Pin-Lui
Inserter
Inserter
Posts: 27
Joined: Fri Apr 01, 2016 12:09 pm
Contact:

Re: run a lua file from console

Post by Pin-Lui »

yeah would be a solution too, i have to figure out how to do own console command what runs my script

Pin-Lui
Inserter
Inserter
Posts: 27
Joined: Fri Apr 01, 2016 12:09 pm
Contact:

Re: run a lua file from console

Post by Pin-Lui »

In the wiki is nothing about how to feed the game engine my own script, i can overwrite everything but i need to insert my own lua to the game functions i guess when i want to access via console... i could be wrong dont know.

ByPaco10
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Feb 05, 2020 5:36 pm
Contact:

Re: run a lua file from console

Post by ByPaco10 »

It worked, thanks

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: run a lua file from console

Post by Honktown »

I use the console for some commands (it doesn't like -- comments).

If it's for certain mods I might unpack the mod and make a change directly

I have a small mod of my own for testing random things or tweaking something for the current game.

For console commands I like to do:

Code: Select all

local commands table = nil

commands_table["name"] = {}
commands_table["name"].command = "what_to_enter_in_console"
commands_table["name"].help = "helpstring"
commands_table["name"].func = function(commandstuff)
  local pid = commandstuff.player_index

end

for _, cmd in pairs(commands_table) do
  commands.add_command(cmd.command, cmd.help, cmd.func)
end
I figured out how to do a custom keyboard command today, so I added a custom keybind to my test mod. The original function just prints a message, and I assign a new local function if I'm messing with stuff.

The control.lua file is re-loaded every time a save is loaded, if the file is in a folder. Don't know about changing a zip, but it's probably not a good idea anyway. Put another way, if you're only changing control.lua code, you don't need to restart the game.
I have mods! I guess!
Link

Post Reply

Return to “Modding help”