[1.3b70] get active variables

If you have an idea for a new feature, please discuss it in the main MapTool forum first, then post a summary of the discussion here. Use the first Sticky as a template.

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Cweord
Great Wyrm
Posts: 1343
Joined: Sun Aug 12, 2007 10:49 am
Location: Midsomer Norton, (Near Bath), UK
Contact:

[1.3b70] get active variables

Post 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.
Cweord

This message has been spell checked by Freudcheck - any mistakes are purley a figment of your imagination.
-------
My Tokens Directory
http://gallery.rptools.net/v/contrib/Cw ... er_Tokens/

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: [1.3b70] get active variables

Post by CoveredInFish »

Maybe this could be another topic for Wiki: getInfo() like getInfo("macro") or something like that.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [1.3b70] get active variables

Post 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), Wiki: getMatchingProperties() and Wiki: getMatchingLibProperties() 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 Wiki: getAllPropertyNames() will return (in the proper case) of the campaign token property names defined for the campaign given the property type name.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: [1.3b70] get active variables

Post 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.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [1.3b70] get active variables

Post 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, Wiki: varsFromStrProp() 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.
Last edited by aliasmask on Wed Jul 28, 2010 11:26 am, edited 1 time in total.

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: [1.3b70] get active variables

Post 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.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [1.3b70] get active variables

Post 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:
Attachments
rpAvatar.png
rpAvatar.png (86.21 KiB) Viewed 803 times

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: [1.3b70] get active variables

Post 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.

User avatar
biodude
Dragon
Posts: 444
Joined: Sun Jun 15, 2008 2:40 pm
Location: Montréal, QC

Re: [1.3b70] get active variables

Post 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. -->
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

Post Reply

Return to “Feature Requests”