Skip to content

Instantly share code, notes, and snippets.

@m-doescode
Created November 17, 2022 10:03
Show Gist options
  • Select an option

  • Save m-doescode/5958982b9c28ee2db940b3963fe49108 to your computer and use it in GitHub Desktop.

Select an option

Save m-doescode/5958982b9c28ee2db940b3963fe49108 to your computer and use it in GitHub Desktop.
ComputerCraft | charmap.lua | Simple charmap for listing all characters and their codes [Advanced Computer only]
-- Made by m-doescode
local w = 16
function dispchar(i,bg,fg)
local x = i % w + 1
local y = math.floor(i / w) + 1
local char = string.char(i)
if bg then
term.setBackgroundColor(bg)
end
if fg then
term.setTextColor(fg)
end
term.setCursorPos(x,y)
term.write(char)
end
for i = 0, 255 do
dispchar(i)
end
term.setCursorPos(term.getSize())
term.setBackgroundColor(colors.red)
term.write("Q")
local sx,sy = term.getSize()
local seli,selx,sely = 0 ,1,1
while true do
local _,btn,mx,my = os.pullEvent("mouse_click")
if mx == sx and my == sy then
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.setCursorPos(1,1)
term.clear()
return
end
if mx <= w then
local i = mx - 1 + (my - 1) * w
if i <= 255 then
term.setCursorPos(selx,sely)
term.setBackgroundColor(colors.black)
term.write(string.char(seli))
term.setCursorPos(mx,my)
term.setBackgroundColor(colors.purple)
term.write(string.char(i))
seli, selx, sely = i,mx,my
local str = "i:" .. i
term.setCursorPos(sx - 6,sy)
term.setBackgroundColor(colors.gray )
term.setTextColor(colors.white)
term.write(str .. string.rep(" ",5 - #str))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment