|
VasoolXanatov Newbie
Joined: 23 Feb 2009 Posts: 8
|
Posted: Sat Dec 18, 2010 4:17 pm
problem determining if string list is null |
Hi. I'm having a problem trying to develop a script. The part where I'm stuck is I need to determine if a string list is null.
There are certain actions I want to take, and only do them if other people are not in the room. The command you send to the mud is WHO HERE. The result displays as follows:
Quote: |
You see the following people here:
Zugg, Vasool, Whiteknight, Jasmine |
So, I am still learning to script I'm a complete amateur, this is probably a poorly written script.
This is the trigger I've got:
Code: |
<trigger name="wh_capture" priority="21410" id="597">
<pattern>You see the following people here</pattern>
<value>#var whpeople {}</value>
<trigger>
<pattern>^(*)$</pattern>
<value>#if (%regex(%1, "\d")) {#state wh_capture 0;#var whpeople {%subregex(@whpeople, "[^\w]+", "|")}} {#var whpeople {%concat( @whpeople, %1)};#state wh_capture 1}</value>
</trigger>
</trigger> |
Which creates something like this if I am the only guy standing in the room:
Code: |
<var name="whpeople" type="StringList" id="596">
<value>Vasool</value>
<json>["Vasool"]</json>
</var>
|
This is the alias that fires off the whole thing to start with.
Code: |
<alias name="whoherecheck" id="594">
<value>#alarm "whohereduh" +1 {
#t+ whohere_capture
}
~who here</value>
</alias>
|
Now, I realize that my name Vasool will always be in that list, no matter what. So I want to be able to put in my script a way to check if any other name is in that list.
Solutions I've tried so far: I've tried doing #DELI whpeople Vasool but it still leaves me with a string list with an empty space no. 1. So when I try to check it using #show %null(whpeople) I still get a value of 0 that shows on the screen. I don't understand what I'm doing wrong here.
Is there another way of checking if there are names other than my own? Like a way of scouring the list, and ignoring Vasool?
Please help, I only started coding a few weeks ago and I'm so frustrated with what should be such a simple thing. Reading the help manuals in the Cmud program do very little to teach, the tutorials are the most basic things, and none of it really gets into stuff like what I'm trying to do so the forums seem to be my only place to educate myself. |
|
Last edited by VasoolXanatov on Sat Dec 18, 2010 7:16 pm; edited 1 time in total |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Dec 18, 2010 6:51 pm |
Just because the game sends you a list of names that will always include your own doesn't mean you have to include your name in the list you assign to the variable.
$people_here = %list(%replace(%remove("Vasool",%1),",,",","))
Now that your name is taken care of, you can then simply use %numitems() or %null() to check for emptiness:
#if (%numitems($people_here)) {do stuff}
#if (%null($people_here)) {do stuff}
Note that if you use %numitems, by checking for a specific limit (ie, %numitems(...) >= 2) you don't need to mess with trying to pull your name out of the list. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Sun Dec 19, 2010 1:45 am Re: problem determining if string list is null |
VasoolXanatov wrote: |
Solutions I've tried so far: I've tried doing #DELI whpeople Vasool but it still leaves me with a string list with an empty space no. 1. So when I try to check it using #show %null(whpeople) I still get a value of 0 that shows on the screen. I don't understand what I'm doing wrong here. |
You were getting a value of 0 after doing this because when you type #show %null(whpeople) you are forgetting the @ to indicate whpeople is a variable. |
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
VasoolXanatov Newbie
Joined: 23 Feb 2009 Posts: 8
|
Posted: Sun Dec 19, 2010 7:19 pm |
Thanks, you're absolutely right. And I was able to figure out two different ways to solve my problem. I appreciate the advice!
|
|
|
|
|
|
|
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
|
|