Posted 20 August 2015 - 11:12 PM
Trying to pull the chat event and run it through a few conditionals….
The event is called 'glasses_chat_command' from what I can tell, but this only returns the event name and the side the peripheral is on.
For Example
Would print:
;(
CODE:
The event is called 'glasses_chat_command' from what I can tell, but this only returns the event name and the side the peripheral is on.
For Example
while true do
local event, side = os.pullEvent("glasses_chat_command")
print("Event: "..event.." Side: "..side)
end
Would print:
Event: glasses_chat_command Side: top
;(
CODE:
glass = peripheral.wrap("top")
cell = peripheral.wrap("bottom")
colors = {
WHITE = 0xFFFFFF,
BLACK = 0x000000,
LIGHTGRAY = 0xC0C0C0,
DARKGRAY = 0x808080,
RED = 0xFF0000,
ORANGE = 0xFF7F00,
YELLOW = 0xFFFF00,
LIME = 0x7FFF00,
DARKGREEN = 0x008000,
LIGHTBLUE = 0x38B0DE,
DARKBLUE = 0x0000FF,
PURPLE = 0x800080
}
WIDTH = 200
HEIGHT = 25
HOFFSET = 5
VOFFSET = 3
TITLE = "POWER"
SCREEN = 490
TOGGLE = true
BOX_ALPHA = 0.2
GRADIENT_ALPHA1 = 0.2
GRADIENT_ALPHA2 = 0.2
ALPHA_OVERIDE = true
ALPHA_OVERIDE_INT = 0.8
function draw(power)
if TOGGLE then
if ALPHA_OVERIDE then
BOX_ALPHA = ALPHA_OVERIDE_INT
GRADIENT_ALPHA1 = ALPHA_OVERIDE_INT
GRADIENT_ALPHA2 = ALPHA_OVERIDE_INT
end
glass.addBox(HOFFSET, VOFFSET, HOFFSET+WIDTH, VOFFSET+HEIGHT, 0xFFFFFF, BOX_ALPHA) -- x,y, x,y, colorHex, alpha
glass.addGradientBox(HOFFSET+5, VOFFSET+5, HOFFSET+WIDTH-10, VOFFSET+HEIGHT-10 ,colors.RED, GRADIENT_ALPHA1, colors.ORANGE, GRADIENT_ALPHA2, 2)
glass.addText((WIDTH/2)-string.len(TITLE), (HEIGHT+VOFFSET)/2, TITLE, colors.LIGHTBLUE)
end
end
function send(side, power)
if rednet.isOpen(side) == false then
rednet.open(side)
end
rednet.broadcast(power)
end
function chatCommands()
local event, message = os.pullEvent("glasses_chat_command")
print(event)
print(message)
if message == "sync" then
glass.sync()
elseif message == "toggle" then
TOGGLE = not TOGGLE
end
end
while true do
glass.clear()
-------------------------
power = cell.getEnergyStored()
draw(power)
send("left", power)
chatCommands()
-------------------------
glass.sync()
sleep(0.1)
end
Edited on 20 August 2015 - 09:18 PM