Page 1 of 1

run a lua file from console

Posted: Fri Apr 01, 2016 12:16 pm
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.

Re: run a lua file from console

Posted: Fri Apr 01, 2016 12:59 pm
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.

Re: run a lua file from console

Posted: Fri Apr 01, 2016 1:29 pm
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.

Re: run a lua file from console

Posted: Fri Apr 01, 2016 8:38 pm
by Adil
Well, you could wrap them in events or interface commands inside a mod, but there's no trivial solution.

Re: run a lua file from console

Posted: Fri Apr 01, 2016 8:40 pm
by Pin-Lui
yeah would be a solution too, i have to figure out how to do own console command what runs my script

Re: run a lua file from console

Posted: Sat Apr 02, 2016 12:58 pm
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.

Re: run a lua file from console

Posted: Wed Feb 05, 2020 7:38 pm
by ByPaco10
It worked, thanks

Re: run a lua file from console

Posted: Thu Feb 06, 2020 8:31 am
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.