Page 1 of 1

simple highligher

Posted: Fri Oct 18, 2013 12:20 pm
by icesteruk
So for past week I been trying to make a simple highlighter as Ive tried to use the one on the forums but seems wont do what im after..

I have
Code: [show] | [select all] lua

function addEnemy(name)

name = name:title()
if mayhem.list.enemies == nil then
mayhem.list.enemies = {}
end

if not table.contains(mayhem.list.enemies, name) then
table.insert(mayhem.list.enemies, name)
end
if mayhem.list.highlighter.color[name] then killTrigger(mayhem.list.highlighter.color[name]) end

mayhem.list.highlighter.color[name] = tempRegexTrigger("\\b(?i)" .. name .. "\\b", [[colorAllInLine(matches[1], mayhem.list.highlighter.enemycolor)]])

cecho("<red>" .. name .. " <white>has been added as an enemy")

end


to Enemy the person.

So my question is HOW Would I store that so when I login again it doesn't 'disappear' and I have to redo it all again?

Re: simple highligher

Posted: Fri Oct 18, 2013 3:12 pm
by Tagon

Re: simple highligher

Posted: Fri Oct 18, 2013 3:41 pm
by icesteruk
Tagon wrote:Short answer, database: http://wiki.mudlet.org/w/Manual:Database_Functions
Don't know how to use databases, guess I'll keep searching online, Thanks

Re: simple highligher

Posted: Fri Oct 18, 2013 3:44 pm
by Tagon
That's why I posted the link :)

Re: simple highligher

Posted: Fri Oct 18, 2013 4:12 pm
by icesteruk
Tagon wrote:That's why I posted the link :)
And YES Ive looked at the link way before you posted it, STILL DONT KNOW HOW TO DO THEM

Re: simple highligher

Posted: Fri Oct 18, 2013 7:23 pm
by Jor'Mox
You can use table.save and table.load to store a regular table in an external file. Then you save it when you add new info, and load it when you connect. No need to mess with databases.

Re: simple highligher

Posted: Fri Oct 18, 2013 8:05 pm
by Vadi
I'd use tables as well. This highlighting script makes use of them as the backend as well.

Re: simple highligher

Posted: Sat Oct 19, 2013 8:16 am
by icesteruk
Jor'Mox wrote:You can use table.save and table.load to store a regular table in an external file. Then you save it when you add new info, and load it when you connect. No need to mess with databases.
But how would I recall the 'name' to be highlighted??

Re: simple highligher

Posted: Sat Oct 19, 2013 3:17 pm
by Jor'Mox
Well, I use a table that uses names as keys, and stores various info about people in a sub table as the corresponding value... So when I have a word that might be a name that I need to highlight, I check to see if there is a value for that word in my name table, and if there is, I highlight it.

So maybe something like this:
Code: [show] | [select all] lua
if nameList[name] then -- if you need to check for things like a trailing 's, you need to be a bit more careful here
   selectString(name,1) -- if you are concerned with the same name showing up twice in a line, you need something a bit more involved here
   setFgColor(r,g,b) -- assign values here as appropriate
end

Re: simple highligher

Posted: Sat Oct 19, 2013 5:02 pm
by icesteruk
Jor'Mox wrote:Well, I use a table that uses names as keys, and stores various info about people in a sub table as the corresponding value... So when I have a word that might be a name that I need to highlight, I check to see if there is a value for that word in my name table, and if there is, I highlight it.

So maybe something like this:
Code: [show] | [select all] lua
if nameList[name] then -- if you need to check for things like a trailing 's, you need to be a bit more careful here
   selectString(name,1) -- if you are concerned with the same name showing up twice in a line, you need something a bit more involved here
   setFgColor(r,g,b) -- assign values here as appropriate
end
Thanks :)

I rewriting the highlighter thing on forums but made it use a variable like 'list.enemy' so I just have to do, colorEnemy(nameoftable) when logged in. and I save said table when I logout etc as I do with everything else

Thank tho ALOT, :)