simple highligher

Post Reply
icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

simple highligher

Post 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?

Tagon
Posts: 24
Joined: Thu Sep 19, 2013 8:38 pm

Re: simple highligher

Post by Tagon »


icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: simple highligher

Post 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

Tagon
Posts: 24
Joined: Thu Sep 19, 2013 8:38 pm

Re: simple highligher

Post by Tagon »

That's why I posted the link :)

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: simple highligher

Post 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

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: simple highligher

Post 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.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: simple highligher

Post by Vadi »

I'd use tables as well. This highlighting script makes use of them as the backend as well.

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: simple highligher

Post 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??

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: simple highligher

Post 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

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: simple highligher

Post 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, :)

Post Reply