altering/subbing a prompt

Post Reply
Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

altering/subbing a prompt

Post by Caled »

Code: Select all

My prompt:
H:5175/5175|4854/4854 B:100% Exp:28 [kdb eb lr] 100|100 Kai:0
Pattern:
H:(\d+)/(\d+)\|(\d+)/(\d+) B:(\d+)% Exp:(\d+) \[(\w+) ([eb-]{2}) ([lr-]{2})\] (\d+)\|(\d+) Kai:(\d+)
My (intended) prompt after the trigger fires:
H:5175|4854 B:100% [kdb eb lr] Kai:0 <a_variable_value>
As you can see, for a lot of that, I want to store in variables but not display in the actual prompt. I am not really sure how to go about this, however. I think the following will work, but it seems like a lot of lines and I wonder if there is a more efficient way to do this (maybe with a trigger chain?):

Code: Select all

selectCaptureGroup(3)
replace("")
selectCaptureGroup(5)
replace("")
replaceAll("/", "")

selectCaptureGroup(7)
replace("")
selectString(" Exp:",1)
replace("")

selectCaptureGroup(11)
replace("")
selectString("|",2)
replace("")
selectCaptureGroup(12)
replace("")
Problem 2:
I wish to add some things to the prompt as well. The value of 'curebals', as well as the values of health_change and mana_change. I am not sure whether I ought to select the entire prompt line with selectString(matches[1]), move the cursor to the end and then use insert(), or to use suffix()

There seem to be multiple ways to do this (as expected), but I am not sure which way is best. the suffix() function may just be a short-cut to doing the exact same thing. So, if anyone has advice on technique, I will appreciate it very much.

Edit: I have tried suffix, but am not sure how to make it work. The following does nothing:

Code: Select all

----- Damage Change -----
if diffH ~= 0 then
	selectString(matches[1])
	suffix(" <" .. diffH .. ">")
end

if diffM ~= 0 then
	selectString(matches[1])
	suffix(" <" .. diffM .. ">")
end
If I do not use the selectString line, it replaces the whole prompt rather than sticking it on to the end. But with the selectString line there (which is selecting everything the trigger matches, right?) it simply doesn't work.

Tips?

Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

Re: altering/subbing a prompt

Post by Caled »

Code: Select all

focus
You focus your mind intently on curing your mental maladies.
H:5175|4604 B:100% [kcdb eb lr]  Kai:0
                       <-250>
H:5175|4604 B:100% [kcdb eb lr]  Kai:0
Your mind is able to focus once again.
H:5175|4604 B:100% [kcdb eb lr]  Kai:0
H:5175|4604 B:100% [kcdb eb lr]  Kai:0
H:5175|4684 B:100% [kcdb eb lr]  Kai:0
                        <80>
H:5175|4684 B:100% [kcdb eb lr]  Kai:0
That is how it appears when I use

Code: Select all

----- Damage Change -----
if diffH ~= 0 then
   suffix(" <" .. diffH .. ">")
end

if diffM ~= 0 then
   suffix(" <" .. diffM .. ">")
end
Is this a bug or am I using it incorrectly?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: altering/subbing a prompt

Post by Heiko »

Why not simply parse the prompt and set the variables you need accordingly. In a second step you'll delete the prompt text and write your own instead. That's a lot simpler.
Have a look at the string.format() function. http://lua-users.org/wiki/StringLibraryTutorial

Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

Re: altering/subbing a prompt

Post by Caled »

The only reason is that I don't know how to duplicate the colouring of the prompt.

CMUD:

Code: Select all

#substitute {H:%ansi(green)$h%ansi(white)~|%ansi(green)$m %ansi(white)B:%ansi(red,hi)$b~% etc}

To duplicate the changing prompt colours:
#substitute {H:%switch($h<$mh*/0.33, %ansi(red,hi), $h<$mh*0.66, %ansi(yellow), %ansi(green))$h%ansi(white)~| etc .... }
( ^ that is just the H: 4244 bit of the prompt, coloured green, then yellow when under 2/3 max health, and red if in the lowest third).

I looked into how to do anything remotely similar in lua, and couldn't find it. I don't see how string.format can help, though it may do. Its hard to find any examples of its use. The explanation of the function in the link you posted means nothing to me, sorry!

Code: Select all

somepromptdisplayfunction( "H:" .. curH .. "|" .. curM .. " B:" .. curB .. " [" .. pstats .. " " .. eqbal .. " " .. armb .. "]" .. "Kai:" .. kai)
How do I display that, where the H: is white, the | is white, the values of curH and curM are green, while curB is red, the [ and ] are white, the values of the variables within being green. 'Kai:' being white etc?

How do I add:
" <" .. diffH .. ">"
when the value of diffH is not 0?
(I would also like to colour this green when it is positive, and red when negative)

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

Re: altering/subbing a prompt

Post by Vadi »

My sipper makes use of string.format. Can't help you with coloring though, it's not that easy on Mudlet I'm afraid (think you'll have to manually use fg and bg inbetween the echos, so it'll be a long, long thing).

Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

Re: altering/subbing a prompt

Post by Caled »

So really, it would be easier if I could figure out how to make suffix() work. Its displaying on a new line rather than at the end of the prompt. I guess there is no reason I could not just use echo() in place of where I was trying to use suffix()

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

Re: altering/subbing a prompt

Post by Vadi »

I think suffix relies on the cursor position, and that is at the beginning of the next line by default. So what we want to do is move it one line up and to the end of it...

Code: Select all

moveCursor("main", getLastLineNumber() -1, 0)
moveCursor("main"), getLastLineNumber(), getColumnNumber() -1
I think. Moves cursor one up and then to the end of the line.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: altering/subbing a prompt

Post by Heiko »

Using echo() will do fine as it prints at the end of the line. The Lua suffix() function from Akkumu may not be correct anymore. Need to look at the code.

Post Reply