Page 1 of 2
Capture a whole block of text
Posted: Thu Oct 24, 2013 7:00 pm
by branden7
Ok..Im moving on to (what I think) is more complicated stuff.
I want to capture a whole block and output it to another window.
IE:
Skill Name Uses Remaining Level
Biting 293 5
Parry 473 5
Shadow Strike 188 5
Climbing 419 5
Close Combat 196 14
Hiding 1056 20
Wound Mending 128 8
Ranged Combat 986 10
Sneaking 1204 18
Swimming 0 100
Unarmed Combat 884 9
Dodge 297 3
Bundling 191 2
Digging 390 6
Fishing 491 5
Skinning 382 4
Wood Chopping 443 5
Mining 956 10
Stone Sculpting 125 2
Speculating 788 8
Cooking 200 2
Fire Building 428 5
Foraging 446 5
I want to grab all of that, and send it to a skill window.
This is very probably a little bit more complicated than basic forum help.
If you guys could just give me an idea of the psuedo-code behind that and methods I could use, i can probably fill in the rest.
My basic idea is to start matching at the line Skill Name, and then copy line by line until I encounter an empty line, and I guess store each line in some sort of array (table in lua right?).
Does that make sense? What all would I need to use for that?
Lastly, I do have a lot of questions, and when you guys get tired of answering them that's fine..I dont expect you all to spend your time teaching me every aspect of Mudlet.
Re: Capture a whole block of text
Posted: Thu Oct 24, 2013 7:23 pm
by xabre
Well, simplest solution would be matching each of those lines and outputing them individually. Yeah, seems like a long list but it just works(TM).
If a prompt line comes right after the list, check wiki on making trigger chains, make trigger
Code: Select all
^Skill Name Uses Remaining Level$[/quote]
and make a chain that will output every incoming line after it till the prompt is recieved.
You have examples both on wiki and here on forum.
Re: Capture a whole block of text
Posted: Thu Oct 24, 2013 7:55 pm
by demonnic
You should look into
tempLineTrigger() for this, perhaps. If the output is something that you kick off, you can create an alias which sets the trigger to use a function of your divising. You can check the output of the 'line' variable which holds the string equivalent of the current line from the server. Combine this with the isPrompt() function (if your mud uses telnet GA signals at the prompt) and you can do something like the following
alias' code:
if skillTempTrigger then
killTrigger(skillTempTrigger)
skillTempTrigger = nil
end
skillTempTrigger = tempLineTrigger(0,99,[[skillTriggerWork()]])
and then in a script:
function skillTriggerWork()
if isPrompt() then
killTrigger(skillTempTrigger)
skillTempTrigger = nil
end
copy()
appendBuffer("MySkillWindow") --obviously, this will change
--uncomment if you want to remove the line from the main console
--deleteLine()
end
Keep in mind, this is all from my head and untested, but it should get you started. You could also make a trigger which is disabled and matches on any line (lua trigger type, text is "return true"), and in the alias enable it. Then make a child trigger which matches your prompt and disables the trigger.
How you go about it is really kind of up to you, but those are two options which should work.
Re: Capture a whole block of text
Posted: Thu Oct 24, 2013 9:03 pm
by branden7
I dont think I get GA signals (it said <no GA> at bottom) but I like the idea..maybe I can just use a regex to match for my prompt because it does send a prompt after I check my skill list. I could tie it into a keystroke too possibly.
If I can't figure that out the second one should work..I think I get the idea there.
Ill let you know what I end up with, and thanks once again.
Re: Capture a whole block of text
Posted: Thu Oct 24, 2013 9:21 pm
by branden7
Ok..so the results of each line are stored in a line variable.
It have it working..kind of. I can't get it to stop but I will figure out a way for it to stop when it hits my prompt (open to suggestions).
and then I'm thinking of putting it the results into a table and outputting the table into a label.
**IT would actually work best if I could test for a blank line of text. ***that doesnt actually quite work...I need it to ignore the first blank line, then match on the next blank line.
Will keep playing with it.
Re: Capture a whole block of text
Posted: Thu Oct 24, 2013 9:52 pm
by demonnic
Ok, but the first line of text after the headers is a blank line of text. Wouldn't it quit out before it got everything?
If you're already matching your prompt in a trigger, just add the following to the bottom of that trigger:
if skillTempTrigger then
killTrigger(skillTempTrigger)
skillTempTrigger = nil
end
And your prompt trigger should go ahead and stop the tempLineTrigger.
Re: Capture a whole block of text
Posted: Thu Oct 24, 2013 9:56 pm
by branden7
Oh man! what the heck. Why didnt I think of that. That's good. That works.
and now I'm late for work.
I should have realized that would work.
Re: Capture a whole block of text
Posted: Fri Oct 25, 2013 4:43 am
by branden7
So I ended up having to change a few things around.
While the kill trigger in the prompt was brilliant and did work, the problem was that sometimes the prompt was coming long enough after the call to display the skills that it was picking up garbage. So I needed to go back to it dieing when it hit a new line..I added a counter and checked for both a count and a blank line.
The other problem had to do with the way that Geyser labels for. The appendBuffer method just doesn't seem to work. There is probably an easier way to do what I am doing that I don't know about, but this seems to work. Here is what it looks like:
--initialize vars
skillTable = {}
skillCounter = 0
--Function to build the the table
function skillTriggerWork()
if (string.find(line, "[a-z]") == nil) and (skillCounter > 3) then
killTrigger(skillTempTrigger)
skillTempTrigger = nil
formatSkillTable() --ok, we are done collecting data. Call this to display it
skillCounter = 0 --reset counter
for k in pairs (skillTable) do --this wipes the table out.
skillTable[k] = nil
end --end for
end --end if
skillCounter = skillCounter + 1 --cant seem to find a better way to increment
table.insert(skillTable, line)
--deleteLine()
end
--function to output the table
function formatSkillTable()
skillOutput = table.concat(skillTable, "<br>")
clearWindow("GUI.Box6");
GUI.Box6:echo("<pre>" .. skillOutput);
end
Then it's called when on a keystroke that both sends "skills" to the MUD and calls the function.
If you see any way to make the run better do let me know.
Re: Capture a whole block of text
Posted: Fri Oct 25, 2013 5:19 pm
by demonnic
Ahh, yes, appendBuffer is for miniconsoles. echo is the way to do it with labels.
As for resetting the skillTable, why not just use skillTable = {} to get an empty table back again? Will have the same effect as setting all of the keys to nil.
Re: Capture a whole block of text
Posted: Sat Oct 26, 2013 12:12 am
by branden7
uhm...I don't know. Ha..
I guess I was thinking that would just create a new reference and leave the old table just hanging out reference-less but still taking up memory, but that probably really isnt a very big deal even if that is the case.