 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Sun Jan 16, 2011 2:51 am
[Solved] Way to Check if a Value Exists? |
Is there a way to see if a certain Variable, Alias, Trigger, Event, etc... exists, not simply whether or not if it's null? I'm in a situation where I have a variable which will be null from time to time and yet, in order to make it work in other scripts which may or may not need it for the script to run, but, will, optionally use if it is there, I need to know if the actual variable exists. Is there any way to do that?
|
|
_________________ Listen to my Guitar - If you like it, listen to more
Last edited by chamenas on Sun Jan 16, 2011 4:56 am; edited 2 times in total |
|
|
 |
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Sun Jan 16, 2011 3:15 am |
Have you tried %defined()? Not sure if it will work for triggers or events. it works for variables I know. %class will work to tell you if just about anything exists if it is nameable. -1 non existent, 0 disabled, 1 enabled.
|
|
_________________ 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 Jan 16, 2011 3:20 am; edited 1 time in total |
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Sun Jan 16, 2011 3:18 am |
That might do it! ;)
I was looking for a %isexist or %exist, didn't think to check %defined
%class and %trigger exist for both of those. Neato, :) |
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Jan 16, 2011 6:12 pm |
%class() and %trigger() are two names for the same function.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sun Jan 16, 2011 7:41 pm |
Except that %class and %trigger aren't just for class and trigger, apparently. They return true if the parameter is an alias. I wonder if that's a bug, then? :\
|
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Sun Jan 16, 2011 8:33 pm |
No, it is not a bug. Originally %class only worked on classes, but that was long ago and far away...or something :) It was deliberately extended to work on all Cmud settings, and the documentation specifically mentions that.
|
|
|
 |
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Sun Jan 16, 2011 8:33 pm |
since the help file for both says they work for any "named" setting I wouldn't consider it a bug but that's just me.
|
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Mon Jan 17, 2011 5:31 am |
Since Variables can also have three states: Enabled, Disabled, Non-existent, I feel as though perhaps one function should just be made called exists.
Syntax: %exists(object[, type])
object represents a named setting: Variable, Function, Alias, Class, Trigger, Event, Macro, etc...
type an optional parameter which allows you to narrow searches when you might have more than one of the same name over a couple of different objects, it would be numerical (1-Variable, 2-Alias, etc...)
Returns: 1-Enabled, 0-Disabled, -1-Does not exist |
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Jan 17, 2011 3:49 pm |
Well, %class already works on variables. So, what you are suggesting is essentially an optional second parameter to %class to specify a type, right? There's no reason to change the name of the function, since you would still have to keep the %class function for backward compatibility.
|
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Mon Jan 17, 2011 8:35 pm |
%class just isn't a very intuitive name (unless it was just for classes). You could keep class and add the "new" function and sort of transition over to it in a couple major versions.
|
|
|
 |
|
|