Problem With ${!Defined[]}

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

BlackTooth
a lesser mummy
a lesser mummy
Posts: 50
Joined: Mon Dec 08, 2003 10:32 am

Problem With ${!Defined[]}

Post by BlackTooth » Sun Jun 27, 2004 10:39 pm

This is an if statement in a macro that I am working on

Code: Select all

/if ( !${Defined[timeFrame]} ){
	/echo No TimeFrame value Specified. Assuming Seconds 
	/varset timeFrame s
	}	
For some reason I get an error when I run the macro ingame....

Is there something wrong with the syntax?

thnks..

User avatar
ieatacid
Developer
Developer
Posts: 2727
Joined: Wed Sep 03, 2003 7:44 pm

Post by ieatacid » Sun Jun 27, 2004 11:11 pm

Code: Select all

/if (!${timeFrame}) {
   /echo No TimeFrame value Specified. Assuming Seconds
   /varset timeFrame s
   }

wassup
Official Guardian and Writer of TFM
Official Guardian and Writer of TFM
Posts: 1487
Joined: Sat Oct 26, 2002 5:15 pm

Re: Problem With ${!Defined[]}

Post by wassup » Sun Jun 27, 2004 11:50 pm

BlackTooth wrote:This is an if statement in a macro that I am working on

Code: Select all

/if ( !${Defined[timeFrame]} ){
	/echo No TimeFrame value Specified. Assuming Seconds 
	/varset timeFrame s
	}	
For some reason I get an error when I run the macro ingame....

Is there something wrong with the syntax?

thnks..
${Defined[]} Just checks for the variable being declared.

What ieatacid did checks if the variable was set to a non zero or non-null value.

Rusty~
a hill giant
a hill giant
Posts: 244
Joined: Wed Apr 14, 2004 2:55 pm

Post by Rusty~ » Mon Jun 28, 2004 4:12 am

to set timeFrame to "s" if it's not defined, change this line:

Code: Select all

/varset timeFrame s
to:

Code: Select all

/declare timeFrame string local s

BlackTooth
a lesser mummy
a lesser mummy
Posts: 50
Joined: Mon Dec 08, 2003 10:32 am

Post by BlackTooth » Tue Jul 06, 2004 11:01 pm

oh kewl thanks fer the help guys works great now

Chill
Contributing Member
Contributing Member
Posts: 435
Joined: Fri May 07, 2004 5:06 pm
Location: Erie, PA

Post by Chill » Wed Jul 07, 2004 3:51 am

If you need to use persistent (Global) variables for a macro, and you are unsure if it will be defined or not, here is the general code block I use:

Code: Select all

/if (${Defined[timeFrame]}) { 
   /varset timeFrame s
} else {
   /declare timeFrame string global s
}
Im guessing you noticed it, but you also need a space between the () around your /if condition and the { starting the code block.