An Easy to Integrate In-Game Console

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
varunprime
Prole
Posts: 6
Joined: Sun Apr 12, 2015 12:30 am
Contact:

An Easy to Integrate In-Game Console

Post by varunprime »

demo.png
demo.png (272.02 KiB) Viewed 4570 times
I recently upgraded one of my old libraries to LOVE 11.3. I figured people might find it useful - https://github.com/rameshvarun/love-console

It's a single file in-game console that you can use for debugging your games. It's easy to integrate and doesn't take over your game loop or install any globals.

Code: Select all

local console = require "console"

function love.keypressed(key, scancode, isrepeat)
  console.keypressed(key, scancode, isrepeat)
end

function love.textinput(text)
  console.textinput(text)
end

function love.draw()
  console.draw()
end

-- This table is available as "player" in the console scope.
console.ENV.player = {x = 100, y = 5}

console.COMMANDS.save = function()
  -- This function is run when the user types "save" into the console.
end
User avatar
Gunroar:Cannon()
Party member
Posts: 344
Joined: Thu Dec 10, 2020 1:57 am

Re: An Easy to Integrate In-Game Console

Post by Gunroar:Cannon() »

Yeah!! I totally fond it useful. I've wanted something like this for a while.

Edit:*found, not fond :P
Last edited by Gunroar:Cannon() on Sat Jun 12, 2021 2:11 pm, edited 1 time in total.
Why can't pirates code in lua? Because they spend to much time at C! :P

-It might look like nonsense :roll: but there's so much proof.
-Some more if you pls... :? .
It has to be real then, all that talk about the end :shock: .
-How to be saved :huh:
User avatar
Xii
Citizen
Posts: 97
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: An Easy to Integrate In-Game Console

Post by Xii »

Looks simple, clean, and very useful, indeed. Thanks for sharing, will probably use. :)
User avatar
Xii
Citizen
Posts: 97
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: An Easy to Integrate In-Game Console

Post by Xii »

Was delightfully simple to integrate. Only needed a tiny tweak:
The tilde key ~ on my keyboard layout (finnish) is somewhere else, so I added:

Code: Select all

function console.enable(enable)
	enabled = enable
	return enabled
end
In order to map the console to F1 instead:

Code: Select all

function love.keypressed(key, scancode, isrepeat)
	if key == "f1" then
		console.clear()
		console.enable(not console.isEnabled())
	end
	console.keypressed(key, scancode, isrepeat)
end
Last edited by Xii on Thu Jun 10, 2021 2:18 am, edited 1 time in total.
User avatar
Xii
Citizen
Posts: 97
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: An Easy to Integrate In-Game Console

Post by Xii »

I see references in the code to colored text, but console.draw() doesn't actually draw colored text. Incomplete functionality?
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests