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
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Sat Nov 27, 2010 6:39 pm   

How to pop a list name acquired from a pattern
 
Hey guys, slight problem again Rolling Eyes

My trigger pattern is: (%w) tells you 'hello'.

Now what i was to do is bring up a first message that is stored in "%1hello" stringlist, to tell %1 that message and remove it from the list, so what i try to do is:

tell %1 %pop(%1hello). However this doesnt work and neither does %pop(@{%1hello}) or any other bracket combination that i have tried to come up with.

What is the proper way to do this?
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Sat Nov 27, 2010 6:49 pm   
 
I tested this for about an hour and while #show does show a proper line being captured, i.e::

zugg tells you 'hello'
#show %1hello shows zugghello and #show (@%1hello) shows @zugghello and while @zugghello stringlist contains test as its first line, %pop(@%1hello) does not bring the test line.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sat Nov 27, 2010 6:58 pm   
 
Is your string list variable actually called %1hello? if so that's the % sign is the problem change the variable name so it doesn't start with % and it should work. Or are you using %1hello to represent a variable called zugghello if zugg sent you a tell?
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Sat Nov 27, 2010 7:05 pm   
 
Im using %1hello to represent a variable called zugghello if zugg sends me a tell. And zugghello is the stringlist that i am trying to %pop.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sat Nov 27, 2010 7:46 pm   
 
Try this.
Code:
<trigger priority="10" id="1">
  <pattern>(%w) tells you 'hello'. </pattern>
  <value>$stringlist = %dbvalues(@%1hello)
#deln @%1hello 1
#send tell %1 %pop($stringlist)
</value>
</trigger>
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Sat Nov 27, 2010 8:19 pm   
 
Ok thanks Fizgard, managed to figure it out, again not exactly what i wanted but it does manage to work.
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Sat Nov 27, 2010 9:12 pm   
 
Hmm, actually it doesnt work, too tired to figure it out now, will try tomorow.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sat Nov 27, 2010 9:38 pm   
 
This may or may not work better, if the first example wasn't exactly what you were looking for.

Code:
<class name="tells" id="1">
  <var name="stringlistVarName" id="2"/>
  <trigger priority="10" id="3">
    <pattern>(%w) tells you 'hello'.</pattern>
    <value>//The next two lines need to be added to any trigger you want to use the @popstringlist function on.
//define the variable you wish to pop a string from, hello can either be literal or access something stored in another variable.
stringlistVarName = %concat("@",%1,"hello")
@popstringlist(@StringlistVarName)

#send tell %1 @poppedstring</value>
  </trigger>
  <func name="popstringlist" id="4">
    <value>//#var poppedstring {%pop($name)}

#var poppedstring {%item($name,1)}

#deln @stringlistVarName 1</value>
    <arglist>$name</arglist>
  </func>
  <var name="poppedstring" type="String" id="5"/>
</class>


I can't seem to find a way to define a variable to pop with wild cards in the actual trigger. This uses a function to do the popping and then remove the popped string from the stringlist.

**EDIT**
Made a small adjustment just in case %pop() does start to remove the item from the stringlist, when used in a User Defined Function, one day.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34

Last edited by Fizgar on Sun Nov 28, 2010 2:07 am; edited 2 times in total
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sat Nov 27, 2010 10:36 pm   
 
You can't have @popstringlist(@StringlistVarName) by itself, Fizgar.

You'll need to put #CALL in front of it. :P
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sun Nov 28, 2010 12:25 am   
 
I know you need to use #call with some of functions that start with %. I hardly ever use #call with my user created functions though. Reguardless the above works just fine without it.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
shalimar
GURU


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

PostPosted: Sun Nov 28, 2010 12:57 am   
 
#DELN is deleting the first value same as %pop does, the current code is gonna eat through your list of hellos without replacing anything.

Assuming you do in fact want the hello list to loop around, try this instead:

Code:
<trigger priority="10" id="1">
  <pattern>(%w) tells you 'hello'.</pattern>
  <value>$stringlist = @{%concat(%1, "hello")}
$stringlist=%additem(%item($stringlist, 1), $stringlist)
#send tell %1 %pop($stringlist)
#EXEC {%1hello = $stringlist}</value>
</trigger>
 
_________________
Discord: Shalimarwildcat
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sun Nov 28, 2010 1:00 am   
 
That is incorrect Shalimar as %pop isn't deleting the item from the list when used in the function for some reason.

**Edit**
What Shalimar just posted, is probably a little faster than my last example due there being less calls maybe? Anrok specified in his first post he wanted the items removed from the list after they are sent in a tell (at least that's how I read it), so you could remove the loop portion increasing speed a bit more probably. I did this and it worked fine till you reach the last item which remains in the list, so he would probably want something to remove the last item once it is sent too.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Sun Nov 28, 2010 11:22 am   
 
Thanks guys, i have incorporated Fizgars first example into my script now and it works just as i would expect %pop(@%1list) to work if it would, except that when i pop $stringlist which contains "@%1list" it doesnt pop the actual list, so #deln @%1list 1 is required to delete the first line from the real "@%1 list"..

Thanks again for all the help, there's just no chance i would've figured that out on my own!
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Sun Nov 28, 2010 12:37 pm   
 
Hmm, not going to start another topic as this is of lesser importance, but can anyone please tell me if its possible to retrieve the largest or smallest value from either a stringlist or a database variable ? Im guessing %dbmax and %dbmin arent applicable to database variables and stringlists ?
So basically if i have a database of 3 keys with values : a=5 b =6 and c = 4, is it possible for CMUD to show either C or B as smallest/largest values ?
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sun Nov 28, 2010 9:40 pm   
 
Here's something you can play around with. if you type getmax followed by the name of a variable (without the @), that has it's type set as either a stringlist or db record, the alias will return the maximum value in either the stringlist or db record. if your dbvar above with the values of a=5|b=6|c=4 was named test, and you typed getmax test the alias would print to the screen, Item #2 in the dbvar has the highest value: b = 6.

Code:
<alias name="getmax" id="2">
  <value>$key = ""
$value = ""
$position = ""
#switch (%vartype(%1) = "record")
    {
      #forall @{%1} {#if (%item(@{%1},%i) > $value) {$value = %item(@{%1},%i);$key = %dbkey(@{%1},%i);$position = %i}}
      #show Item #$position in the dbvar has the highest value: $key = $value
    }
  (%vartype(%1) = "stringlist")
    {
      #forall @{%1} {#if (%item(@{%1},%i) > $value) {$value = %item(@{%1},%i);$position = %i}
      }
      #show Item #$position in the string list has the highest value of $value.
    }

</value>
</alias>
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Sun Nov 28, 2010 9:55 pm   
 
Great stuff! Now why cant this be a built-in cmud function ? : (
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Nov 29, 2010 6:32 pm   
 
The %dbmin and %dbmax are part of the Database Module and don't actually work with normal variables...they only work with tables/views in the database module.

However, the normal %min and %max functions *do* work with normal database variables and return the smallest and largest value in a list or db variable. For example:

#SHOW %min(@test)

would show 4 in your example above. If you want to display the key value, you can use this:

#SHOW %dbkey(@test, %isvalue( @test, %min(@test)))

and it will show "c".
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Fri Dec 03, 2010 1:40 pm   
 
awesome Zugg, thanks!
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