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 Goto page 1, 2  Next
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Tue May 13, 2008 4:19 pm   

working with stringlist... (starting over)
 
I'm starting to confuse myself I'm afraid. I'm trying to rebuild an old script that used an array, and I'm having issues with converting over to a string list. Here is the jist of things...

When I first enter a room. I've got two triggers set up {@gob_list} and a {@sob_list} that works at seeing the mobs that are in there. Those two are a stringlist. Now. My first issue, is working with this information. For example....

This is one mob A here.
This is one mob B here.
There are [ 4 ] of mob C here.
There are [ 2 ] of mob D here.

Here are the two predefined variables:

#var {sob_list} {There is one mob A here.|There is one mob B here.}
#var {gob_list} {of mob C here.|of mob D here.}

Now I also have predefined variable @key_list that contains the mobs name.

#var {key_list} {A|B|C|D}

And a @mob_list that holds the amount of each mob... (which should change as I kill the mobs, and/or I move rooms. I'd also like to manipulate this as mobs enter and leave the room, but thats more for later)

#var {mob_list} {1|1|4|2}

Now what I'm having a problem with, is manipulating @mob_list. Meaning... If there is no mob, if there are mobs, single or muliple. I need it to change the corresponding number in @mob_list to reflect how many (if any) of the mob name and the trigger. All... Of course, tied in to each other. After I get that solved, I'm going to move to my next issue. LoL! TIA, and... If this is confusing, or you need more information, I'll do my best to put it down for ya. Thanks!!! =D
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue May 13, 2008 5:11 pm   
 
One immediate problem you will have is that string lists do not stay in the order you create them. That is, if you create it as {A|B|C|D} it may display later as {B|D|A|C}. So, you will lose the relationship between key_list and mob_list.

What you actually want is a database variable, like so:
#var mob_list {A=1|B=1|C=4|D=2}

Look up Database Variables on cmud help. To change one of the values, do:
#addkey mob_list A 4

That should make your life much simpler. Smile
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Tue May 13, 2008 5:14 pm   
 
Stringlists items should stay in the order created or added unless the SORT flag is set
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue May 13, 2008 5:24 pm   
 
Bleh, I'm probably getting mixed up with database variables, which don't stay in order.

In any case, a db variable is probably the right solution for what Shaun wants. It's a lot easier than figuring out which index to change.
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Tue May 13, 2008 6:27 pm   
 
So... If I don't use the SORT flag, then they will stay in order... Correct? And my problem still is here. Going to look into the database variables. See if maybe that will be a better route. Not really concerned about simplicity (as eventually I will get it all sorted out) more worried about speed. FAST FAST FAST!! =D
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue May 13, 2008 7:00 pm   
 
Unless you have a huge number of mobs in your lists, speed is not an issue. Cmud is fast fast fast. Lookup in a database variable will be faster than determining the index of a value in a string list, but we are talking tiny lookup times on any reasonable size string list.

If you can explain a little more precisely what you need, we can help further.
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Tue May 13, 2008 7:08 pm   
 
So ok... I am not 100% sure that this will work. But how about this then?

Code:
#var {sob_list} {A=This is one mob A here.|B=This is one mob B here.|B=This is one mob C here.|D=This is one mob D here.}

#var {gob_list} {A=There are ~[ (%d) ~] of mob A here.|B=There are ~[ (%d) ~] of mob B here.|C=There are ~[ (%d) ~] of mob C here.|D=There are ~[ (%d) ~] of mob D here.}

#trig {{@sob_list}} {#addkey mob_list {A=1|B=1|C=1|D=1}}

#trig {{@gob_list}} {#addkey mob_list {A=%1|B=%1|C=%1|D=%1}}


edit: Had to fix that code. PS... What I'm trying to do, is load predefined moblist of a certain area, and then when I get into the room, inventory specifically what mobs are in there, how many, and the systematically go thru and KEEEAAAAL! =]
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue May 13, 2008 7:39 pm   
 
When you use a data record variable in a trigger, the keys (not the values) are concatenated into key1|key2|key3. This is useful for stuff like:

#trig {({@recordvar})} {#addkey seenmobs %1 (%db(@seenmobs,%1)+1)}

Or something.

Let me see if I have this correct. You have a list of mobs that you want your script to be looking for, and when those mobs are encountered, you want the count added to a variable so you know how many of each of the mobs you're interested in are in the room. You can either do that with a generic trigger that fires on ALL mobs in the room and captures them - then you look through for the ones you're after, or you can use a dbvar whose keys are the exact strings that appear in the room, then have the variable in the pattern. Each key's value is reset to 0 when you move in this method, whereas in the previous, you can just clear the variable completely. It's up to you which you'd rather do.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue May 13, 2008 7:51 pm   
 
If I am understanding correctly, the mud will list each type mob on a line of its own. So the triggers should only change one mob value at a time. The way you have it, a line reading "This is one mob A here." will set A, B, C, and D all to 1. You need a way to capture the name of the mob and use that in the addkey.

How about this: let us say that the mobs are Horse, Cow, Pig, and Chicken.
#var {sob_list} {Horse|Cow|Pig|Chicken}
#var {mob_list} {Horse=0|Cow=0|Pig=0|Chicken=0}
#trig {This is one (@sob_list) here.} {#addkey mob_list %1 1}
#trig {There are ~[ (%d) ~] of (@sob_list) here.} {#addkey mob_list %1 %2}

Even better, I recall reading on the forum recently that using a database variable in a trigger pattern uses just the keys, so you may not even need a separate @sob_list:

#var {mob_list} {Horse=0|Cow=0|Pig=0|Chicken=0}
#trig {This is one ({@mob_list}) here.} {#addkey mob_list %1 1}
#trig {There are ~[ (%d) ~] of ({@mob_list}) here.} {#addkey mob_list %2 %1}

I assume that the mud won't say "There are 0 of mob A here." That means you need one more thing to make this work. You need to reset the values to 0 every time you enter a new room. That will probably be another trigger. Is there some text that always preceeds the list of mobs? If you can find something to trigger on, you just need:

#trig {appropriate initializing text} {#addkey mob_list {A=0|B=0|C=0|D=0}


Last edited by Rahab on Tue May 13, 2008 7:56 pm; edited 2 times in total
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Tue May 13, 2008 7:54 pm   
 
FANG! Your avatar changed! LoL!

Well.. Probably whatever is easiest. As I'm starting from scratch, and finding I really don't know as much as I thought I did!

I'm thinkging that the dbar might be the way to go, so that I can change later, depending on the area, or whatever else I'm trying to acccomplish. Sounds the most dynamic. You got me a little confused. So it should read (for the trigger):

#trig {({gob_list})} {#addkey mob_list %1 (%db(@mob_list,%1)+1)}
#trig {({sob_list})} {#addkey sob_list %1 1}

Right? And when I first get into the room, all the keys should = 0 already... So only if there is a mob in the room that matches either the gob_list and/or sob_list will it get added. Am I correct in this thinking?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue May 13, 2008 8:00 pm   
 
Yeah, I change it every couple of weeks if I remember. Collect the full set! ;)

This script (if you add the @s to the pattern like you should and if you correct your triggers so that gob_list or mob_list is used throughout) will add 1 to the value of whichever key matched. So if you were to do:

#addkey gob_list "a hairy marmot" 0

Then every time the words "a hairy marmot" appeared, 1 would be added to the hairy marmot count. I hope you can see how that works - it adds a new key (overwriting the old one) that's got the value of the old one +1. Your sob_list's values will only ever be 1, no more.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Tue May 13, 2008 8:07 pm   
 
Rahab -- I guess that works, but the problem is, that the triggers are each different. IE a Horse, Cow, Pig, and Chicken would have a completly different line then each other. For example (along with the initializing trigger that could be used)

[ Exits: North South ]
Galloping by, a horse nearly runs you over.
There is a cow grazing in the field.
In the distance you see [ 2 ] pigs rolling in the mud.
There are [ 8 ] chickens in a flock, clucking making noise.

[ Lag: 0 ] [ Reply: MySelf ]
[H: 100/100] [M: 100/100] [S: 100/100] [E: 100/100]

So then you would have... For example:

#var {sob_list} {Galloping by, a horse nearly runs you over.|There is a cow grazing in the field.|Rolling in the mud, a pig makes a mess.|One chicken got seperated from the flock.}

#var {gob_list} {A stallion leads a herd of ~[ (%d) ~] horses around.|There are ~[ (%d) ~] cows here eating away at the grass.|In the distance you see ~[ (%d) ~] pigs rolling in the mud.|There are ~[ (%d) ~] chickens in a flock, clucking making noise.}

#var {mob_list} {Horse=0|Cow=0|Pig=0|Chicken=0}

#trig {^~[ Exits:} {#addkey mob_list {Horse=0|Cow=0|Pig=0|Chicken=0}}

#trig {({@sob_list})} {#addkey mob_list %1 1}

#trig {({@gob_list})} {#addkey mob_list %1 %2}


Right?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue May 13, 2008 8:20 pm   
 
Ah, yes, if the phrases are different, something like that will work. You still need to capture the name of the mob, though, for the #addkey. Something like:

#var {sob_list} {Galloping by, a (horse) nearly runs you over.|There is a (cow) grazing in the field.|Rolling in the mud, a (pig) makes a mess.|One (chicken) got seperated from the flock.}

#var {gob_list} {A stallion leads a herd of ~[ (%d) ~] (horse)s around.|There are ~[ (%d) ~] (cow)s here eating away at the grass.|In the distance you see ~[ (%d) ~] (pig)s rolling in the mud.|There are ~[ (%d) ~] (chicken)s in a flock, clucking making noise.}

I'm actually not sure whether the () captures will work inside a list like that. Also, you need to swap the %1 and %2 in the last trigger:

#trig {({@gob_list})} {#addkey mob_list %2 %1}


Or you can go with Fang's idea, which is a bit different.
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Tue May 13, 2008 8:26 pm   
 
Ok... Another wrench in the gears!!! =D

Say for example, the mobname is NOT in the trigger. Like so....

[ Exits: North ]
Galloping by, a horse nearly runs you over.

[ Lag: 100 ]

But the mobname is stallion. But... Isn't the name of the mob defined in the @mob_list? And I think I'm going to go this route ATM, cuz I feel I've got a better handle on how things flow this way. LoL! Unless... Its not 'effective'... *shrug*
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue May 13, 2008 8:36 pm   
 
Ooh, getting tricky! Very Happy

I'm running out of time today, so I'll just put out a quick idea. Make @sob_list a db variable, as you started to do at one point:

#var {sob_list} {Galloping by, a horse nearly runs you over.=Stallion|There is a cow grazing in the field.=Bull|Rolling in the mud, a pig makes a mess.=Sow|One chicken got seperated from the flock.=Rooster}

Then in your trigger, use %line as a key in @sob_list to find the right value to use as the key in @mob_list. Good luck!
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Tue May 13, 2008 8:53 pm   
 
Ok. Got the db variable down. Not sure how you mean to use the %line. The syntax is %line(num) right? Would the @gob_list trigger be the same? Thanks for everyone's help by the way! =D

This?

Code:
#trig {({@sob_list})} {#var mob_list %line(1)}
#trig {({@gob_list})} {#var mob_list %line(%1)}
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed May 14, 2008 1:19 pm   
 
I realized after I logged out yesterday that what I described would work for @sob_list, but not for @gob_list. The phrases you have for @gob_list have an unknown numerical value in them, so you can't use that as your key. So, we may have to use another layer of indirection.

But in any case, I have discovered a problem in using captures within a stringlist. I'm about to post about it. I'll think about alternative methods for a bit.
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Wed May 14, 2008 2:35 pm   
 
Well... Here is the OLD triggers... Maybe that will help a lil? Keep in mind that doing it this way, @key_list is a list of the mob names. That, and the @gob_list would only have the trigger off of the line, but off of the part AFTER the ]. Finally... It is using an array, which I am trying to move away from...

Code:
#trig {{@sob_list}} {#NOOP %arrset( mob_list, %eval( %ismember( %item( @key_list, %ismember( %trimright( %line), @sob_list)), @key_list) - 1), %eval( %arrget( mob_list, %eval( %ismember( %item( @key_list, %ismember( %trimright( %line), @sob_list)), @key_list) - 1)) + 1))}

#trig {{@gob_list}} {#IF (%ismember( %trimright( %left( %line, %eval( %pos( ~[, %line) - 1))), @gob_list)) {#NOOP %arrset( mob_list, %eval( %ismember( %item( @key_list, %ismember( %trimright( %left( %line, %eval( %pos( ~[, %line) - 1))), @gob_list)), @key_list) - 1), %eval( %arrget( mob_list, %eval( %ismember( %item( @key_list, %ismember( %trimright( %left( %line, %eval( %pos( ~[, %line) - 1))), @gob_list)), @key_list) - 1)) + %copy( %line, %eval( %pos( ~[, %line) + 2), %eval( %eval( %pos( ~], %line) - 2) - %eval( %pos( ~[, %line) + 2) + 1))))} {#NOOP %arrset( mob_list, %eval( %ismember( %item( @key_list, %ismember( %trimleft( %right( %line, %eval( %pos( ~], %line) + 1))), @gob_list)), @key_list) - 1), %eval( %arrget( mob_list, %eval( %ismember( %item( @key_list, %ismember( %trimleft( %right( %line, %eval( %pos( ~], %line) + 1))), @gob_list)), @key_list) - 1)) + %copy( %line, %eval( %pos( ~[, %line) + 2), %eval( %eval( %pos( ~], %line) - 2) - %eval( %pos( ~[, %line) + 2) + 1))))}}
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Wed May 14, 2008 2:58 pm   
 
Would this work then?

Code:
no...  rethinking....
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed May 14, 2008 3:08 pm   
 
I've done some experiments, and it looks like #var has problems when the key has spaces in it. But we can use #addkey instead. Here is my next try.
Code:

#addkey sob_list {Galloping by, a horse nearly runs you over.=Stallion|There is a cow grazing in the field.=Bull|Rolling in the mud, a pig makes a mess.=Sow|One chicken got seperated from the flock.=Rooster}

#addkey gob_list {horses around.=Stallion|cows here eating away at the grass.=Bull|pigs rolling in the mud.=Sow|chickens in a flock, clucking making noise.=Rooster}

#var {mob_list} {Horse=0|Cow=0|Pig=0|Chicken=0}

#trig {^~[ Exits:} {#addkey mob_list {Horse=0|Cow=0|Pig=0|Chicken=0}}

#trig {({@sob_list})} {#addkey mob_list %db(@sob_list,%1) 1}

#trig {~[ (%d) ~] ({@gob_list})} {#addkey mob_list %db(@gob_list,%2) %1}

This avoids having captures within the stringlist itself. For gob_list, the stringlist only contains the part of the phrase after the numeral.
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Wed May 14, 2008 3:54 pm   
 
Why does my *_list keep reording itself? Everytime I try to delete it, and readd it, it changes. Even when I manually move things around in the xml, it realigns it when I save it. Does the matter actually order tho, since they are have a unique key, that corresponds with each other?
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed May 14, 2008 3:59 pm   
 
It's DB variable not a stringlist, so the order is irrelevant, you refer to the entries using the key.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Wed May 14, 2008 4:05 pm   
 
Heh... Yea, I just checked it out! It works like a champ!! =D Ok... Now that I've gotten that down (I actually changed up this a little....)

Code:
#trig {^~[ Exits} {resetmobs}
#alias {resetmobs} {#var {mob_list} {Horse=0|Cow=0|Pig=0|Chicken=0}}


Reason being, is that depending on the area, that class will be enabled, and each area will have a unique alias inside it. But that trigger isn't inside the area script, as I need that trigger for other aspects.

Ok... Now that works like a champ. I need to figure out a way to go thru that list, kill it, and remove it from the 'todo' list. Gonna post my thoughts on that in a minute. Thanks for your help everyone! =D
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed May 14, 2008 5:04 pm   
 
Here's an idea. For resetmobs:
Code:

#alias {resetmobs} {#var mob_list {}}

That will clear @mob_list completely. You can use the same variable @mob_list for all of your areas. In each room it will be populated only by the mobs that are there.

For the next part, I'm not sure if you want an alias, a trigger, or what. So I'll just make some code that could go in either. The easy way to loop through the list would be #loopdb. Then perhaps another loop based on the number of each specific mob. Something like:

#loopdb @mob_list {#loop %val {some code to kill mob %key}}

The problem with this simplistic code is that you need to break the loop if something unexpected happens. For instance, if you suddenly move to the next room while still in the middle of your fight, the loop will still continue. So instead, how about a piece of code that simply checks whether there is a mob on the list to kill, and attacks it:

Code:

#local $nextmob $newval
#loopdb @mob_list {
  #if (%val > 0) {
    $nextmob = %key
    $newval = %val - 1
    #addkey mob_list %key $newval
    #break
  }
}
#if ($nextmob <> "") {kill $nextmob} {#show no more mobs}
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Wed May 14, 2008 6:15 pm   
 
Ok... I think I see what your try'n to do. Gonna test it out. I'm not worried about moving QUITE yet... I'm more concerned about the triggers that are being used, and if it will initiate combat before the mob is actually dead. I've got the trigger part figured out... Its a case sensitive trigger...

[H: 100/100] [S: 100/100] [M: 100/100] [E: 100/100] <)---- not in combat
[h: 100/100] [s: 100/100] [m: 100/100] [e: 100/100] <)---- in combat
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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