 |
Carpesimia Beginner
Joined: 06 Feb 2025 Posts: 18
|
Posted: Tue Apr 08, 2025 1:42 am
Multi Line Capture |
Yeah, I've searched, but honestly I dont see what I am looking for, so figured I post something.
So for my current need, I am trying to capture the inventory I am carrying, so I can find (and drop) junk items easier. Here's what part of my "inventory" looks like:
Quote: |
You are currently holding:
item1(itemnum) torch(2837) pouch(8812) item(822) item(232)
anotheritem(2201) andanother(1501) coin(1212)
You are currently wearing:
... ... ... |
There are 2 spaces in front of the itemlist on each line, just not in the quoteblock. That being said, I cant just trigger on that because other sections of the inventory are also spaced as such, for readability purposes.
So, what I want to do, when I enable the trigger and type "i" for inventory, is somehow collect a list of all of the item numbers in parentheses, only in between the "You are currently holding" and "You are currently wearing" lines. This could be EMPTY, meaning i am holding nothing. Or it could be 1 item, or 10 lines of items. My intention is to create a list of these items, and then compare to a list of items that, if they're in that list, to drop or bury or whatever. I already have some logic to manage the "action list", but I cant for the dickens figure out how to grab the data in between those lines. I could PROBABLY figure out how to tokenize them as well (id probably like to end up with 2 lists. One by name, and one by number. Only because I MAY want to do something with the name later on.
Anyways. Ideas? Thoughts? Point me to another link?
As always, appreciate the input. |
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4753 Location: Pensacola, FL, USA
|
Posted: Tue Apr 08, 2025 4:26 am |
Here is the XML of a trigger:
Code: |
<trigger priority="539480" id="53948">
<pattern>You are currently holding:</pattern>
<trigger type="Within Lines" param="1" repeat="true">
<pattern>(%w)~((%d)~)</pattern>
<value>#STATE 1
$name=%1
$num=%2
$this=%db(@itemNumDB, $num)
#ADDKEY $this Name $name
#ADDKEY $this Held 1
#ADDKEY itemNumDB $num $this</value>
</trigger>
</trigger> |
Something like this should start you on the way to building out a database variable, which i find much easier than sql.
Values can be accessed by %db calls and/or #SHOWDB (often used together depending on how deep your stuff is nested), or the dot notation syntax of: @itemNumDB.1234.Name
#HELP #command
#HELP %function
will pull up the help files, and if you have any questions, feel free to ask. |
|
_________________ Discord: Shalimarwildcat |
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4753 Location: Pensacola, FL, USA
|
Posted: Tue Apr 08, 2025 5:17 am |
The trigger type of within lines, along with param, tell it that the condition is active until x lines have printed to the screen before the trigger state updates.
The #STATE command is playing off this fact by resetting the state each time it matches, to allow it to try the next x lines for another match.
The repeat value just means the pattern can match more than once on a single line.
Between the two it should match and capture all the key value pairs. |
|
_________________ Discord: Shalimarwildcat |
|
|
 |
Carpesimia Beginner
Joined: 06 Feb 2025 Posts: 18
|
Posted: Tue Apr 08, 2025 6:11 pm |
Thank you, Shalimar. I'll absolutely try this tonight!
|
|
|
 |
Carpesimia Beginner
Joined: 06 Feb 2025 Posts: 18
|
Posted: Tue Apr 08, 2025 6:59 pm |
Ok I got impatient. Please bear with my dumb questions.
First, what is the "$varname" notation? Thats new to me. Ive been using #TEMP and #VAR variables exclusively. -- Found this in the help! Local vars, assuming local to the script. That will be handy.
Second, this trigger seems to only catch the first iteration on each line. so:
You are currently holding:
item1(itemnum) torch(2837) pouch(8812) item(822) item(232)
anotheritem(2201) andanother(1501) coin(1212)
Only begets me item1 and anotheritem, leaving the other 6 items not accounted for. I see the checkbox "Repeat within line" but i changed the DB logic to just #SAY the values, and I only see each once.
Even in the wizard where I usually pre-test my trigger strings, it only matches the first iteration on the line. |
|
Last edited by Carpesimia on Tue Apr 08, 2025 8:12 pm; edited 1 time in total |
|
|
 |
Carpesimia Beginner
Joined: 06 Feb 2025 Posts: 18
|
Posted: Tue Apr 08, 2025 7:28 pm |
Hmm. So, with further investigation, i noticed "repeat within line" on the inside trigger smehow got turned off. When i turn it back on, I ONLY see the very first item on the very first line. Not the other lines after it.
When I turn off repeat within line, it shows the first item from all lines.
I cant help but feel I'm missing something really basic here. I am pretty sure I grok your example, but in practice its not working as I thought.
Actual mud output:
(with repeat within lines turned off)
rock(62) talc(51) raft(138) tote(45) smokes(157)
rock :: 62
ball(20) pebble(34) marble(17) bauble(26) necklace(2403)
ball :: 20
candy(155) ring(246) obsidian(735)
candy :: 155
(with repeat lines turned on)
rock(62) talc(51) raft(138) tote(45) smokes(157)
rock :: 62
ball(20) pebble(34) marble(17) bauble(26) necklace(2403)
candy(155) ring(246) obsidian(735)
(In above examples, those are the items after "You are currently holding:" until that pattern is no longer present)
The line with "item :: number" is set by the inner trigger. |
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4753 Location: Pensacola, FL, USA
|
Posted: Wed Apr 09, 2025 3:02 am |
okay, so $var indicates a #LOCAL @var
i.e, a variable that only exists within the {brackets} it is defined in
very handy for data you don't need to save past the now and is only being defined for ease of reference
a whole bunch of nested functions gets to looking ugly in a hurry, and becomes harder to understand at a glance
as for in not capturing them all...
lets try parsing %line instead |
|
_________________ Discord: Shalimarwildcat |
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4753 Location: Pensacola, FL, USA
|
Posted: Wed Apr 09, 2025 3:08 am |
Code: |
<trigger priority="539480" id="53948">
<pattern>You are currently holding:</pattern>
<value>//Reset stuff goes here, if needed</value>
<trigger type="Within Lines" param="1">
<pattern>*</pattern>
<value>#IF (%match( %line, "(%w)~((%d)~)")) {
#STATE 1
$list=%replace( %trim( %line, " ", "|"))
#FORALL $list {#IF (%match( %i, "(%w)~((%d)~)", $name, $num)) {
$this=%db( @itemNumDB, $num)
#ADDKEY $this Name $name
#ADDKEY itemNumDB $num $this
}}
}</value>
</trigger>
</trigger> |
|
|
_________________ Discord: Shalimarwildcat |
|
|
 |
Carpesimia Beginner
Joined: 06 Feb 2025 Posts: 18
|
Posted: Wed Apr 09, 2025 4:12 pm |
You are absolutely awesome. This one has gotten me most of the way there. This data is ephemeral and only needed for a short time, so I'd rather use lists than the DB. Which is good, I've got it working.
But, that being said, I have run up to a hopefully simple issue. How do I empty a list, without having to loop through it and delete the items one at a time? |
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4753 Location: Pensacola, FL, USA
|
Posted: Thu Apr 10, 2025 1:05 am |
Local variables get flushes automatically with the closing curly brace.
but for a standard variable list:
itemList=%null
will clear it, or you can use #UNVAR to delete it
You can also give the variable a default value, and it will reset when you open the session or use #RESET. |
|
_________________ Discord: Shalimarwildcat |
|
|
 |
Carpesimia Beginner
Joined: 06 Feb 2025 Posts: 18
|
Posted: Thu Apr 10, 2025 11:47 am |
Thank you again. %null is what I was looking for. #UNVAR seemed to send a message to the screen every other time I used it (and only seemed to work when the message was sent). the %null works perfectly every time without a message in the middle of the scroll. thanks again!
|
|
|
 |
|
|