ConsoleBox!
Posted: Sat Sep 12, 2015 4:42 pm
Hi! I create this 'script' because whenever I do a game and I need "in game console" I had a problem with scrolling text(Write all times same script)... Whatever, it's still in beta but it working right now and it's easy to implement into YOUR AWESOME GAME!
Using:
To add message to box use:
Code of consolebox.lua:
If you want to add scrolling option implement into
To give user option for writing just add into
And this is it. You can edit this code if you want to work different. And remember this is on beta, not all works perfect!
Using:
Code: Select all
require 'consolebox'
function love.load()
cb.load()
end
function love.draw()
cb.draw()
end
Code: Select all
cb.addMs(put string here)
Code: Select all
local utf8 = require("utf8")
cb = {}
function cb.load()
messages = {}
ms = -15
ms2 = 0
input = ""
end
function cb.draw()
if messages[ms] then love.graphics.print(messages[ms], 5, 5) end
if messages[ms+1] then love.graphics.print(messages[ms+1], 5, 20) end
if messages[ms+2] then love.graphics.print(messages[ms+2], 5, 35) end
if messages[ms+3] then love.graphics.print(messages[ms+3], 5, 50) end
if messages[ms+4] then love.graphics.print(messages[ms+4], 5, 65) end
if messages[ms+5] then love.graphics.print(messages[ms+5], 5, 80) end
if messages[ms+6] then love.graphics.print(messages[ms+6], 5, 95) end
if messages[ms+7] then love.graphics.print(messages[ms+7], 5, 110) end
if messages[ms+8] then love.graphics.print(messages[ms+8], 5, 125) end
if messages[ms+9] then love.graphics.print(messages[ms+9], 5, 140) end
if messages[ms+10] then love.graphics.print(messages[ms+10], 5, 155) end
if messages[ms+11] then love.graphics.print(messages[ms+11], 5, 170) end
if messages[ms+12] then love.graphics.print(messages[ms+12], 5, 185) end
if messages[ms+13] then love.graphics.print(messages[ms+13], 5, 200) end
if messages[ms+14] then love.graphics.print(messages[ms+14], 5, 215) end
if messages[ms+15] then love.graphics.print(messages[ms+15], 5, 230) end
love.graphics.print(input, 5, 255)
end
function cb.addMs(message)
messages[ms2] = message
if ms2 > ms-15 then ms = ms+1 end
ms2 = ms2+1
end
function cb.mp(x,y, button)
if button == "wu" then
ms = ms - 1
elseif button == "wd" then
ms = ms + 1
end
end
function cb.kp(key)
if key == "return" then
messages[ms2] = input
if ms2 > ms-15 then ms = ms+1 end
ms2 = ms2+1
input = ""
elseif key == "backspace" then
byteoffset = utf8.offset(input, -1)
input = string.sub(input, 1, byteoffset - 1)
else
input = input..key
end
end
Code: Select all
cb.mp(x, y, key)
Code: Select all
function love.mousepressed(x, y, key)
Code: Select all
cb.kp(key)
Code: Select all
function love.keypressed(key)