String manipulation

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

String manipulation

Post by tarrant »

From Lua pattern tutorial directory,
You can see that string.find() returns the start and finish indices of the whole pattern and the captures that we made using brackets in the pattern.
My mud sends me this
A~1053~B~1053
A~1053 means my current health is 1053 and B~1053 means my max health is 1053

So i'm using this code to capture.

Code: Select all

hpCur = x.value:find("A~(%w+)")
hpMax = x.value:find("B~(%w+)")
echo(hpCur) gives me a value of 1.
echo(hpMax) gives me 8.

I'm assuming 1 and 8 are the start indices of the pattern.
My question is how to i get it to return the captures? ie the (%w+).

Sorry if its a stupid question, been searching through all the sites but i can't find it, or i missed it.
Any help would be appreciated.
Thanks.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: String manipulation

Post by demonnic »

Is this coming in as a normal line, or something else? If it's part of, say, your prompt you're better off capturing it in the trigger itself.

A~(\d+)~B~(\d+)


of course if you're getting it some other way, the lua route will be it. I wouldn't use string.find, however, you'd be better off with string.match
Code: [show] | [select all] lua
hpCur = x.value:match("A~(%w+)")
hpMax = x.value:match("B~(%w+)")

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

Re: String manipulation

Post by tarrant »

yeah, its info that the mud can send in the background.
the string.match was exactly what i needed. thanks!

Post Reply