Page 1 of 1

[1.3b70] get active variables

Posted: Wed Jul 28, 2010 7:25 am
by Cweord
What I am looking for is a function that gets a list of the active variables (the names, rather than contents) and outputs them to a string list.

This would be useful for self creating jsons where all you have to input are the list of fields as part of your original input, and the code creates the rest - the biggest advantage being you just have to add to the input to add to the json.

I am working round it with a reference json right now, containing the list of fields used - but it would be nice to be able to self generate.

Re: [1.3b70] get active variables

Posted: Wed Jul 28, 2010 8:39 am
by CoveredInFish
Maybe this could be another topic for [wfunc]getInfo[/wfunc] like getInfo("macro") or something like that.

Re: [1.3b70] get active variables

Posted: Wed Jul 28, 2010 8:46 am
by aliasmask
Cweord wrote:What I am looking for is a function that gets a list of the active variables (the names, rather than contents) and outputs them to a string list.

This would be useful for self creating jsons where all you have to input are the list of fields as part of your original input, and the code creates the rest - the biggest advantage being you just have to add to the input to add to the json.

I am working round it with a reference json right now, containing the list of fields used - but it would be nice to be able to self generate.

I'm a little fuzzy on what you're saying. What is the scope of your active variables? Do you mean a list of variables defined in a macro? Or defined on a token? If you mean defined on a token then there is a function for that (or 2), [wfunc]getMatchingProperties[/wfunc] and [wfunc]getMatchingLibProperties[/wfunc] will list the properties on a token given a filter. To list the all use ".*". The result will return the property names but all in lower case format, but will include "hidden" variables too. Using [wfunc]getAllPropertyNames[/wfunc] will return (in the proper case) of the campaign token property names defined for the campaign given the property type name.

Re: [1.3b70] get active variables

Posted: Wed Jul 28, 2010 8:58 am
by CoveredInFish
If I understood OP right he wants all local variables inside the current macro.

The intended usage is to wrap all variables automatically in a json (variableName->variableValue) for easier parameter submitting to other functions/macros. (Personally I dont find it bad to create these json by hand for tidying up and not submitting unneeded information).

I myself like to see such a functions for its debugging capabilities.

Re: [1.3b70] get active variables

Posted: Wed Jul 28, 2010 10:45 am
by aliasmask
I too wish I could create scopes. I'm a coldfusion programmer and I defined every single one of my variables in a scope (local being L.varname) where passing L would give me access to all my local variables and it definitely helped in debugging. But other than defining the variables in my own custom scope there is no way in coldfusion to automatically get a list of locally defined variables. I don't see that as a common practice.

For MT, I've used in the past, but shy away from it now, [wfunc]varsFromStrProp[/wfunc] to define a bunch of local variables quickly. I don't do it so much now because it's not evident what variables are accessible with in that segment of code, especially if the prop string is passed to the macro or pulled from a property.

Re: [1.3b70] get active variables

Posted: Wed Jul 28, 2010 11:03 am
by Azhrei
(Love the new avatar, alias. :))

There is no way to get a list of "active" variables per se. If you wanted such a list, you would need to maintain it yourself. As alias points out, using L.* for local variables would at least help by letting you know at a glance whether a variable is expected to be local, but it doesn't help in retrieving a list of variable names.

Re: [1.3b70] get active variables

Posted: Wed Jul 28, 2010 11:40 am
by aliasmask
Azhrei wrote:(Love the new avatar, alias. :))

Thanks. My last avatar was my last PC Zuul... now I have a new PC and I added some PSP glitz to it with some runes in the background using the Levitated Rune font. It actually spells out my name :)). You can find a similar image in my gallery. Here's the base image I used for the token tool:

Re: [1.3b70] get active variables

Posted: Wed Jul 28, 2010 11:48 am
by wolph42
Azhrei wrote:There is no way to get a list of "active" variables per se. If you wanted such a list, you would need to maintain it yourself. As alias points out, using L.* for local variables would at least help by letting you know at a glance whether a variable is expected to be local, but it doesn't help in retrieving a list of variable names.
Which is why he posted it in the feat request section ;). I second his request.

Re: [1.3b70] get active variables

Posted: Wed Jul 28, 2010 1:02 pm
by biodude
For macros where I will deal with and process several token properties, I usually do this:
- Define a list of all the property names
- Set local variables with a prefix with the contents of the token properties
- do some processing to the local variables
- set the properties with a loop.

You could do much the same thing with local variables only. I just found it easier to maintain a list, than repeating each option individually.

For example:

Code: Select all

[H: varList = "var1, var2, var3" ]
[FOREACH( var, varList): set( var , "" )]<!-- to initialise. -->
[json.pkg = "{}" ]<!-- empty json container -->
[FOREACH( var, varList): json.set( json.pkg , var, eval( var ) )]<!-- package into a json object -->
[FOREACH( var, varList): setProperty( "bio."+var , eval( var ) )]<!-- set some properties. -->