This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TedRoastBeef's profile picture

Need help with Terminal Glasses

Started by TedRoastBeef, 02 November 2016 - 06:28 PM
TedRoastBeef #1
Posted 02 November 2016 - 07:28 PM
Hey,

Im Trying to create a Console Overlay for custom commands and such.


local bridge = nil
local socket = nil

local sides = {"top","bottom","left","right","back","front"}
local cache = {TedRoastBeef={consoleAccess=true,showConsole=false,output={0xC0FFEE .. "TEST"}}}
local commands = {}

commands["^help$"] = function(player, args) writeLine(player, "INFO", 0xC0FFEE, "HELP COMMAND TRIGGERD") end
commands["^console$"] = function(player, args) print(player) cache[player]["showConsole"] = not cache[player]["showConsole"] end

commands["^whitelist add (.*)$"]=function(player, args) table.insert(cache,{args={consoleAccess=true,showConsole=false,output={}}}) end
commands["^whitelist remove (.*)$"]=function(player, args) table.remove(cache, key) end
commands["^whitelist list (.*)$"]=function(player, args) for key, value in pairs(cache) do writeLine(player,"Info",0xFFFFFF,key) end end

commands["^wl add (.*)$"]=function(player, args) table.insert(cache,{args={consoleAccess=true,showConsole=false,output={}}}) end
commands["^wl remove (.*)$"]=function(player, args) table.remove(cache, key) end
commands["^wl list (.*)$"]=function(player, args) for key, value in pairs(cache) do writeLine(player,"Info",0xFFFFFF,key) end end

function Initialize()
if term.isColor()==false then
        print("ERROR: Not an Advanced Computer!")
        error()
    end

for key, value in pairs(sides) do
        if peripheral.getType(value)=="modem" then
            socket = peripheral.wrap(value)
            rednet.open(value)
        elseif peripheral.getType(value)=="openperipheral_glassesbridge" or peripheral.getType(value)=="openperipheral_bridge" then
            bridge = peripheral.wrap(value)
        end
    end

    if bridge==nil or socket==nil then
        term.setTextColor(colors.red)
        print("ERROR: Missing Modem or Bridge!")
        term.setTextColor(colors.white)
        error()
    end

    bridge.clear() 
end

function writeLine(player, prefix, color, msg)
table.insert(output[player]["output"], color .. "[" .. textutils.formatTime(os.time(), false) .. "][" .. prefix .. "] " .. msg)
end

function InputHandler()
while true do
e, side, player, uuid, msg_raw = os.pullEvent("glasses_chat_command")
for pattern, func in pairs(commands) do
args = string.match(string.lower(msg_raw), pattern)
if args~=nil then
if cache[player]["consoleAccess"] == true then
func(player, args)
end
end
end
end
end

function GraphicsHandler()
while true do
bridge.clear()
for key, value in pairs(cache) do
if cache[key]["showConsole"] == true then
bridge.getSurfaceByName(key).addBox(0,0,500,200,0xFFFFFF,0.2) 

line = 24
if table.getn(cache[key]["output"]) >= 24 then
overflow = table.getn(cache[key]["output"])-24
else
overflow = 0
end
for i = table.getn(cache[key]["output"]),overflow,-1 do

print(i.." | "..overflow.." | "..line.." | "..textutils.serialize(cache[key]))
bridge.getSurfaceByName(key).addText(0, line*8, string.sub(cache[key]["output"][i], 9), tonumber( string.sub(cache[key]["output"][i], 1, 8)))
line = line - 1
end
end
end

bridge.sync()
end
end

function Main()
Initialize()

--cache = loadSettings("config.json")
parallel.waitForAny(GraphicsHandler, InputHandler)
--saveSettings("config.json", cache)
end

function saveSettings(path, object)
file = fs.open(path, "w")
file.write(textutils.serialize(object))
file.close()
end

function loadSettings(path)
file = fs.open(path, "w")
if file then 
data = file.readAll()
file.close()
return textutils.unserialize(data)
end
return {}
end

Main()

If i run this it says bad argument: string expected, got nil

i dont know why i mean it should work.
Edited on 03 November 2016 - 07:22 AM
Bomb Bloke #2
Posted 03 November 2016 - 01:37 AM
Please provide the error in full. The line number in particular is important.
TedRoastBeef #3
Posted 03 November 2016 - 07:42 AM
The Full Error:
Console:80 bios:80: bad argument: string expected, got nil

by the way is there a way to get the with and hight from the terminal glasses?
Edited on 03 November 2016 - 10:43 AM