Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Felix_Gaunt
Beginner


Joined: 07 Mar 2020
Posts: 12

PostPosted: Thu Nov 11, 2021 1:56 am   

How to Increment Lines/Rows?
 
Is there a way when a trigger executes to read the first line that it triggered on then increment to the next line? I get a list of stuff and I can grab the first in the list but not sure how to grab the rest, it would be nice if I could increment until I hit the end which would have another trigger closing out the list.

I get something like this:

/---------------------
| Store Item
| Acme Apple
| Walmart Pear
| Best Buy Speakers
\---------------------

So in the above when I see "| Store" I grab the next line and load Acme and Apple into my database, then I keep incrementing and loading till I get to "\----" then close it out.

Thanks!
Reply with quote
hpoonis2010
Adept


Joined: 18 Jun 2019
Posts: 216

PostPosted: Thu Nov 11, 2021 6:19 am   
 
EG.,

#trigger {/---} {#T+ grabdata}
#addkey database %1 %2
#trigger {\---} {#T- grabdata}

You have a class that contains the pattern(s) for storing the data which enables/disables when you want it.
#trigger {pattern} {
#addkey dbvar store item
}

There is really no 'increment' you just grab each required pattern until you reach a non-matching pattern. HOWEVER, if you have multiple stores with same name (key) then any match after the first will overwrite the first. In which case you would need a unique key and that would mean your key=value 'pair' is now a nested

key="key=value"

In theory you could put the ending pattern into the starting pattern by use of a TEMP trigger but I remain unconvinced that they are totally stable. As in:

#trigger {/---} {
#TEMP endgrab {\---} {#T- grabdata}
#T+ grabdata
}
Reply with quote
Felix_Gaunt
Beginner


Joined: 07 Mar 2020
Posts: 12

PostPosted: Thu Nov 11, 2021 1:03 pm   
 
Hmmm thanks but sadly I don't think this will work. :-/ My problem is it's not as clear cut that a pattern will do it or I would. I have stuff like this:

/----------------------
| Store Item
| Acme Apple
| Pear
| Orange
| Giant Grapefruit
| Banana
\------------------------

So it's not repeating the Store every row like you would say see in Excel, thus my need for a way to increment.
I think I've found a solution with %line, it's going to be a pain but it should work. When I hit the end (which I CAN find out lol) I'll do %line(i) where i starts as 1 and increments until I reach "| Store" then use the resulting value from i to step through the list.
This way if I see Acme as the Store and then a blank in the next row I know that the Store is still Acme and can associate Pear with Acme. Not a GREAT solution but it should work.

P.S. the values above are spaced in the game so the Store always starts in Col 3, Item in Col 90, etc.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4429
Location: Pensacola, FL, USA

PostPosted: Thu Nov 11, 2021 1:59 pm   
 
You want a stated trigger.

Code:
#TR {| Store Item} {}
#COND {(*)} {
  #IF (!%begins(%line, "\-----")) {
    #STATE 1
    $thisItem=%trim(%replace(%line, "|"))
    }
  } {within|param=1}


The first pattern in the #TRIGGER is state 0.
The second pattern in the #CONDITION is state 1.
The {within|param=1} tells it that that condition is only good for exactly one line after the first line is received.
The #IF tests for the closing line, and if it doesn't match, the #STATE forces the trigger to make the condition be active for another iteration.
We test against the closing closing line pattern in the #IF, if it doesn't match, we force it to
_________________
Discord: Shalimar#3679
Reply with quote
Felix_Gaunt
Beginner


Joined: 07 Mar 2020
Posts: 12

PostPosted: Sat Nov 13, 2021 10:57 pm   
 
Thanks shalimar, this works!

Now I am struggling MIGHTLY with the limited functions available to me. Like I know the position of each column but since there appears to be no Mid Function in CMUD I think I need to basically write my own. :-(
Reply with quote
hpoonis2010
Adept


Joined: 18 Jun 2019
Posts: 216

PostPosted: Sun Nov 14, 2021 8:46 am   
 
%len(string)/2 will give you a mid point for odd number of chars and an approximate for even length. You can try

#IF (%mod(%len(string),2)=0)

in a function, which should test for even length or odd.
Reply with quote
faisal70
Newbie


Joined: 25 Nov 2021
Posts: 2

PostPosted: Thu Nov 25, 2021 6:13 am   
 
Hello, thank you very much, I also needed it and I did as a colleague above wrote to set the trigger to 0 thank you very much I looked everywhere and unfortunately I could not find it, but here I finally found on this forum, for sure it will be useful to other people
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net