|
Darkmere Novice
Joined: 23 May 2003 Posts: 31
|
Posted: Sat Jun 07, 2003 11:17 pm
Searching mass variables |
Is there any way to search a class of list variables for information, and collect the variable names into another list?
For example, say I have a class of nothing but this:
#VAR A {a}
#VAR B {a|b}
#VAR C {a|b|c}
#VAR D {a|b|c|d}
#VAR E {a|b|c|d|e}
#VAR F {a|b|c|d|e|f}
Is there some alias I can construct to search all those variables (though there is over 100) for, say the letter d? Then when it finds one with that member, it will add it to a variable called result?
Then result will contain {D|E|F} ?
Any help would be appreciated.
-Darkmere |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Jun 08, 2003 1:29 am |
If you are absolutely 100% certain of all the variables in that class folder, then you can just put the names in a giant stringlist and loop through them. You can then reference each variable in turn so you can examine the contents.
If you are not always sure about the variable names in the folder, there's nothing you can do.
li'l shmoe of Dragon's Gate MUD |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sun Jun 08, 2003 1:36 pm |
Well, if you don't know the name of all the variables in the class, you can get the names, but it requires using COM. Here is an alias that puts the name of all variables in the specified class into a stringlist named @varList:
#ALIAS getVarsInClass {#VARIABLE varList "";#LOOP 0,%eval( %session.NumVars - 1) {#IF (%session.VarNum(%i).ClassName = "%1") {#ADDITEM varList %session.VarNum(%i).Name}}}
Just pass the name of the class as an argument to the alias. Example:
getVarsInClass myClass
Kjata |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Jun 08, 2003 2:08 pm |
As long as your already running a loop on the variables you might as well just test the value.
#ALIAS SearchVarsInClass {#VARIABLE varList "";#LOOP 0,%eval( %session.NumVars - 1) {#IF (%session.VarNum(%i).ClassName = "%1") {#IF (%ismember("%-2",%session.VarNum(%i).Value) {#ADDITEM varList %session.VarNum(%i).Name}}}}
Now it take a first argument of class and the rest as the search value. Example:
SearchVarsInClass myclass look for this
Remember the comparisons used are case-sensitive. |
|
|
|
Darkmere Novice
Joined: 23 May 2003 Posts: 31
|
Posted: Sun Jun 08, 2003 11:14 pm |
Vijilante, you have the exact idea I'm looking for. The only problem is, when I try to put your script in, or the one above yours, I get the same syntax error :
...{#IF (%session.VarNum(%i).ClassName = "%1")...
It points the the ( before the %i
Am I missing something, or is there a prefrence to change for it to work?
-Darkmere |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Jun 09, 2003 4:22 am |
Hrm, I thought that syntax checker problem was fixed back in 6.60. Anyway you can ignore the syntax error.
|
|
|
|
DeathofOne Beginner
Joined: 03 Jun 2003 Posts: 25
|
Posted: Mon Jun 09, 2003 7:01 am |
Hmm, why not use %array Then just check them tends to be easier. Unless you have different reasons to use variables.
Arrays tend to be less memory use and faster to check them or use them (once opened). |
|
|
|
Darkmere Novice
Joined: 23 May 2003 Posts: 31
|
Posted: Mon Jun 09, 2003 8:48 pm |
Could you perhaps expand on your idea, Death? The previous code works perfect for my version, but I have a friend on 6.16 that would like to use the same basic idea : But it doesnt seem to work on his.
Perhaps you could give an example of how %array would work
-Darkmere |
|
|
|
|
|