Echo Console emulates a terminal inside your love2d game. It includes various useful commands, like getvar and setvar, lua, love, etc.
When using the lua command, or any other that runs lua code, the code is called with pcall and has a custom enviroment (that can be modified with the env command) so you errors in the code don't affect your game.
Implementing Echo Console in your project is as easy as writing 6 lines of code into your main.lua (see Post installation)
Echo Console doesn't create any unwanted global variables.
First, clone or add as a submodule:
git clone https://github.com/Nykenik24/Echo-Console.git path/to/echo
# or, if you have a repository
git submodule add https://github.com/Nykenik24/Echo-Console.git path/to/echoThen, require it in your main.lua or the file where you load libraries.
CONSOLE = require("path.to.echo")After installing echo, you need to actually implement it.
To implement echo into your love project, put this into your main.lua:
function love.load()
CONSOLE = require("echo") -- see installation
CONSOLE:init() -- initialize
end
function love.update()
CONSOLE:update() -- update the console
end
function love.draw()
CONSOLE:draw() -- draw when open
end
function love.keypressed(k)
CONSOLE:keypressed(k) -- pass keypresses
end
function love.textinput(t)
CONSOLE:textinput(t) -- pass text input
endAnd that's it! You don't need nothing more, echo will handle text input, keypresses, etc. and draw only when open.
After doing the steps in Post installation, run your game and press the grave accent key (`) to open the console
To change this keybind, use CONSOLE:config("open_keybind", "(new keybind)") or open the console and type conf set open_keybind (new keybind).
After opening the console, you will see three things:
- Two tips, one saying how to get all commands and one saying how to disable tips.
- The "command prompt", the way you execute commands.
Here you will want to type help, as the first tip says, to know what each command does. If you want to know about an specific command, type help (command).
Let's try some commands!
- Type
echo Hello, World!. - Type
msg error Goodbye, World!. - Type
flexists path/to/echo/init.lua. - Type
lua print(2 + 2). - Type
calc 4 * 2 + 6 / 3. - Type
env get allandgetvar all. - Type
lua error("this code is sandboxed and protect-called").
Now create some global variable called TEST_VAR inside your main.lua and add it to the enviroment, then link the global variable with the enviroment variable.
function love.load()
CONSOLE = require("echo")
CONSOLE:init()
TEST_VAR = CONSOLE:setVarInEnv(5, "TEST_VAR")
end
function love.update()
CONSOLE.utils.linkGlobalToEnvVariable("TEST_VAR", "TEST_VAR")
CONSOLE:update()
end
-- Other code...Open the terminal and type getvar TEST_VAR and env get TEST_VAR:
The demo consists of main.lua and conf.lua, to run it use love.
The demo has some unique commands included:
spawn- Spawn a rectangle atx(first arg),y(second arg).despawn- Despawns rectangle with indexi(first arg).randomspawn- Spawn a rectangle at random position.chspeed- Changes rectangle speed.togglepause- Pauses/unpauses the rectangles.
- Demo font: https://github.com/eliheuer/caskaydia-cove


