 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Sat Nov 27, 2010 6:39 pm
How to pop a list name acquired from a pattern |
Hey guys, slight problem again
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? |
|
|
|
 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: 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. |
|
|
|
 |
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: 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 |
|
|
 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: 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.
|
|
|
|
 |
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: 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 |
|
|
 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: 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.
|
|
|
|
 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Sat Nov 27, 2010 9:12 pm |
Hmm, actually it doesnt work, too tired to figure it out now, will try tomorow.
|
|
|
|
 |
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: 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 |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: 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 |
|
|
|
 |
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: 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 |
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4777 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
 |
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: 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 |
|
|
 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: 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! |
|
|
|
 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: 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 ? |
|
|
|
 |
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: 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 |
|
|
 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Sun Nov 28, 2010 9:55 pm |
Great stuff! Now why cant this be a built-in cmud function ? : (
|
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: 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". |
|
|
|
 |
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Fri Dec 03, 2010 1:40 pm |
awesome Zugg, thanks!
|
|
|
|
 |
|
|
|