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 18275 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: 1085
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.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Xii
Party member
Posts: 137
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
Party member
Posts: 137
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
Party member
Posts: 137
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?
User avatar
mozt
Prole
Posts: 5
Joined: Tue Sep 07, 2021 3:11 am

Re: An Easy to Integrate In-Game Console

Post by mozt »

it 's useful ,but maybe a hightlight would be better
:awesome: Bon appetite
MarkD
Prole
Posts: 1
Joined: Wed Jun 29, 2022 12:07 pm

Re: An Easy to Integrate In-Game Console

Post by MarkD »

Hello.
I am new to programming. To do an integration, do I necessarily need to have a very good knowledge of APIs?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 14 guests