I just thought I would share a few functions that people might find useful until the color table is saved by mudlet...
local savemap = db:create("map", {
idcounts = {cid=0},
cckey = {ckey=0, r=0,g=0,b=0,_index = { "ckey" }, _unique = {"ckey"}, _violations = "REPLACE"}
})
function LoadSetup()
local key,ct,r,g,b,lkp
local Oresults = db:fetch(savemap.idcounts)[1]
if Oresults then
GcolorCount = Oresults["cid"];
end
local Oresults = db:fetch(savemap.cckey)
ct=1
while Oresults[ct] do
key = Oresults[ct]["ckey"];r = Oresults[ct]["r"];g = Oresults[ct]["g"];b = Oresults[ct]["b"];lkp = (r.."r"..g.."g"..b.."b");
setCustomEnvColor(key, r, g, b);
ColorKey[key]= {};
ColorKey[key]["r"]= r;
ColorKey[key]["g"]= g;
ColorKey[key]["b"]= b;
ColorLkp[lkp]=key
ct=ct+1
end
--echo("Setup Tables Loaded>")
end
function NewColorID()
--echo("==>")
GcolorCount = GcolorCount + 1
local Oresults = db:fetch(savemap.idcounts)
Oresults[1]["cid"] = GcolorCount
--echo("==>")
db:update(savemap.idcounts, Oresults[1])
return GcolorCount
end
function FindColorCK(RR,GG,BB)
local Cid,huh
local lkp = (RR.."r"..GG.."g"..BB.."b");
--echo(lkp)
if ColorLkp[lkp]~=nil then
Cid = ColorLkp[lkp]
--echo(">")
else
--echo("<creating")
Cid = NewColorID()
--echo("==>"..Cid)
ColorKey[Cid]= ColorKey[Cid]or{};
ColorKey[Cid]["r"]= RR;
ColorKey[Cid]["g"]= GG;
ColorKey[Cid]["b"]= BB;
--display(ColorKey[Cid])
ColorLkp[lkp]=Cid
--display(ColorLkp)
huh=db:add(savemap.cckey,{ckey=Cid, r=RR,g=GG,b=BB})
setCustomEnvColor(Cid, RR, GG, BB);
end;--end--if
--echo(Cid.."<OK")
return Cid
end--function
function FindColor(key)
local r,g,b
if(ColorKey[key])then
r = ColorKey[key]["r"];g = ColorKey[key]["g"];b = ColorKey[key]["b"];
else
r =140;g = 0;b =9;
end
return r,g,b
end
This creates a database to store the colors (load the color table by calling the LoadSetup() function
then... use the function
colorID = FindColorCK(RR,GG,BB)
where RR is red, GG is blue, BB is blue, if color does not yet exist, it creates it and returns the new colorID value else it returns an existing value for that color.
there is also a function to get the rgb value for a colorID
r,g,b = FindColor(ColorID)
...just thought this might be useful to someone.
Omit