From c7090b9381cda803fb314f2d95ee62812712e9b6 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 4 Aug 2022 02:55:14 +0100 Subject: chat --- chat.lua | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/chat.lua b/chat.lua index 6e44d56..879d630 100644 --- a/chat.lua +++ b/chat.lua @@ -8,10 +8,10 @@ M.clear() local Mw,Mh = M.getSize() local scorewidth=10 local lbw = 4+16+scorewidth -local wLog = window.create(M,1,1,Mw-lbw,Mh) --- wLog.setBackgroundColor(colors.blue) --- wLog.clear() --- wLog.write("LOG") +local wLog = window.create(M,1,12,Mw,Mh-12) + wLog.setBackgroundColor(colors.blue) + wLog.clear() + wLog.write("LOG") local wLb = window.create(M,Mw-lbw+1,1,lbw,11) -- wLb.setBackgroundColor(colors.red) -- wLb.clear() @@ -60,7 +60,7 @@ local function draw_lb(W,scores) for name,score in pairs(scores) do table.insert(thescores,{name=name,score=score}) end - table.sort(thescores,function(a,b) return a.score < b.score end) + table.sort(thescores,function(a,b) return a.score > b.score end) for i=1,10 do if not thescores[i] then break end @@ -76,13 +76,7 @@ local function draw_lb(W,scores) end end -draw_lb(wLb,{ - aaa=10, - bbb=100, - ccc=12345, - ddd=234287, - thethethethe=69420, - harold=111222,}) +draw_lb(wLb,) local function score(msg) @@ -91,9 +85,19 @@ local function score(msg) return s end -local userscores = setmetatable({},{__index=function()return 0 end}) + + +local userscores = setmetatable({ + aaa=10, + bbb=100, + ccc=12345, + ddd=234287, + thethethethe=69420, + harold=111222, +},{__index=function()return 0 end}) while true do + draw_lb(wLb,userscores) local _,user,msg = os.pullEvent"chat_message" local s = score(msg) userscores[user] = userscores[user] + s -- cgit v1.2.3