select and replace instead of deleteline

Post Reply
tarrant
Posts: 49
Joined: Thu Apr 15, 2010 10:36 pm

select and replace instead of deleteline

Post by tarrant »

My mud sends me info like
#K%00001008AAC15:41#K%00001011AAF1.5 days
or
#K%00001007BAE0.10
The general pattern is #K% followed by a bunch of info. So each #K% represents 1 piece of info that the mud sends.
Highlighted for easier viewing. Each different colour is a packet. Each quote above is given in 1 line from the mud. And it can go up to 6-8 packets in 1 line.

So i have triggers to capture each packet of info courtesy of tsuujin already, however, the mud doesn't always send a \n at the end of the packet, so sometimes other mud outputs are attached to the end of the packet.
Like
#K%00001008AAC15:41#K%00001011AAF1.5 daysYou punch him in the face!
How should i go about removing the packets without affecting the "You punch him in the face!" ?
I've tried selectString and replace, but when nothing is attached to the end of the packet, then i'm left with a blank line. and this can get really spammy. not to mention ugly.
deleteLine doesn't leave a blank line, but gags the whole thing including You punch him in the face!.

Is there anyway to solve this?
Thanks

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: select and replace instead of deleteline

Post by Knute »

It would appear from what you posted that each packet is a certain length.
You can set up your triggers to capture a certain length.

The pattern to capture one character is: (.)
So, to capture a string of 5 characters you would use: (.....)

I'm sure there are other ways to do it, but I don't know them right at the moment.

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: select and replace instead of deleteline

Post by naftali »

hrm, lessee. Assuming they all look like that, you could probably make a regexp trigger with a pattern like such:

Code: Select all

(#K%[a-zA-z0-:\.9]{16})
For the script use this:

Code: Select all

selectString(matches[2],1)
replace("")
see how that works.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: select and replace instead of deleteline

Post by tsuujin »

You can modify the function I gave you to do this very easily.

This modifies the current function to add the entire line to the returned table as the element "package"
Code: [show] | [select all] lua
function parsePackage(s)
	local charCount = 1
	local pkgCount = 1
	local packages = {}

	while s:find("#K%",charCount, true) do
		charCount = s:find("#K%",charCount, true)
		local pkg = {}
		local ttlString = s:sub(charCount,charCount+8)
		charCount = charCount + 8 -- to get to the important data.
		local x = tonumber(s:sub(charCount,charCount + 2))
		charCount = charCount + 3
		pkg["group"] = s:sub(charCount,charCount + 2)
		pkg["value"] = s:sub(charCount+3,charCount+x-1)
		pkg["package"] = ttlString .. x .. pkg["group"] .. pkg["value"]
		packages[pkgCount] = pkg
		pkgCount = pkgCount + 1
	end

	return packages
end
Once you use your trigger to pass "line" to that function, you'll want then go through and replace all instances of the packages with nothing. You could add to my example script like this:
Code: [show] | [select all] lua
for i,x in pairs(packages) do
	cecho(string.format("<white>%s\n",string.rep("-",20)))
	cecho(string.format("<white>Package %d: %s\n",i,x["package"]))
	cecho(string.format("<white>Group: <yellow>%s\n",x["group"]))
	cecho(string.format("<white>Value: <yellow>%s\n",x["value"]))
	local i = 1
	while selectString(x["package"],i) > -1 do
		selectString(x["package"],i)
		replace("")
		i = i + 1
	end
end
This would ensure that all instances of each individual package get removed from the screen, leaving only what was left at the end of the line.

Post Reply