Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Script made by Oysi
- local this = {}
- -- Declarations
- local open = false
- local text = ""
- local textData = {}
- local textLimit = 10
- local nextBackspace = 0
- local backspaceTime = 0.04
- -- Setup environment
- local env = {}
- for i, v in pairs(_G) do
- env[i] = v
- end
- -- Settings
- function this.setOpen(o) open = o end
- function this.getOpen() return open end
- function this.setTextLimit(t) textLimit = t end
- function this.getTextLimit() return textLimit end
- function this.getEnv() return env end
- -- Functions
- function this.addText(t)
- table.insert(textData, 1, t)
- table.remove(textData, textLimit)
- end
- env.print = this.addText
- -- Draw
- function this.draw()
- -- Draw background
- love.graphics.setColor(50, 50, 50, 200)
- love.graphics.rectangle("fill", 0, 0, love.window.getWidth(), 10 + textLimit*20 + 10)
- -- Draw text data
- love.graphics.setColor(255, 255, 255, 255)
- for i = 1, #textData do
- love.graphics.print(tostring(textData[i]), 10, (textLimit - i)*20)
- end
- -- Draw text
- love.graphics.print("> " .. text, 10, textLimit*20)
- end
- -- Update
- function this.update(delta)
- if love.keyboard.isDown("backspace") then
- nextBackspace = nextBackspace + delta
- if nextBackspace > backspaceTime then
- nextBackspace = nextBackspace - backspaceTime
- text = text:sub(1, -2)
- end
- end
- end
- -- Key pressed
- function this.keypressed(k)
- if k == "return" then
- this.addText("> " .. text)
- local func, err = loadstring("return " .. text)
- if not func then
- func, err = loadstring(text)
- end
- if func then
- setfenv(func, env)
- local success, result = coroutine.resume(coroutine.create(func))
- if success then
- if result then
- this.addText(result)
- end
- else
- this.addText(result)
- end
- else
- this.addText(err)
- end
- text = ""
- elseif k == "backspace" then
- text = text:sub(1, -2)
- nextBackspace = -0.4
- end
- end
- -- Text input
- function this.textinput(t)
- if t == "|" then
- open = not open
- else
- if open then
- text = text .. t
- end
- end
- end
- -- Return
- return this
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement