Retrieving individual variables from a list of nested arrays

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

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

femanon
Cave Troll
Posts: 95
Joined: Sat Jun 16, 2012 10:25 pm

Retrieving individual variables from a list of nested arrays

Post by femanon »

Code: Select all

Propertyname= 
AbilSTR=BaseS=0 ## EnhS=0 ## MoralS=0 ## AlchS=0 ## SizeS=0 ## SacrS=0 ## ProfS=0 ## InhS=0 ## RaceS=0 ## PenaltyS=0 ## DamageS=0 ## DrainS=0 ## LegacyS=0 ## TitleS=0; AbilDEX=BaseD=0 ## EnhD=0 ## MoralD=0 ## AlchD=0 ## SizeD=0 ## SacrD=0 ## ProfD=0 ## InhD=0 ## RaceD=0 ## PenaltyD=0 ## DamageD=0 ## DrainD=0 ## LegacyD=0 ## TitleD=0;

this is basically a type of array I'm trying to stuff inside a property, I'm trying to make things a bit easier to deal with and streamlined, but I'm having trouble drawing individual variables out from this. I would like for it to be able to be done within a property field, similar to the way you can do other evaluations and macroscript, which probably means I probably cannot simnply stuff a particular set in a variable to then call them in another location. How then should I draw from this list say ProfS?


I am trying to create an exhaustive character sheet, one that works without a lib token and has a battery of potential bonuses to certain attributes. if anyone knows a better way to keep track of all these variables that doesn't involve nested lists I'd love to hear it as well,

User avatar
aliasmask
Deity
Posts: 8692
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Retrieving individual variables from a list of nested ar

Post by aliasmask »

This is one way:

Code: Select all

[H: value = json.get(json.fromList(Propertyname,"##"),"ProfS")]

femanon
Cave Troll
Posts: 95
Joined: Sat Jun 16, 2012 10:25 pm

Re: Retrieving individual variables from a list of nested ar

Post by femanon »

this appears to take from the whole list of the property though, I'd like to be able to only select from one list, either AbilSTR or AbilDEX, there are also properties that simply have duplicates.

User avatar
aliasmask
Deity
Posts: 8692
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Retrieving individual variables from a list of nested ar

Post by aliasmask »

Oops, wrong function:

Code: Select all

[H: Propertyname="AbilSTR= ## BaseS=0 ## EnhS=0 ## MoralS=0 ## AlchS=0 ## SizeS=0 ## SacrS=0 ## ProfS=0 ## InhS=0 ## RaceS=0 ## PenaltyS=0 ## DamageS=0 ## DrainS=0 ## LegacyS=0 ## TitleS=0; AbilDEX=BaseD=0 ## EnhD=0 ## MoralD=0 ## AlchD=0 ## SizeD=0 ## SacrD=0 ## ProfD=0 ## InhD=0 ## RaceD=0 ## PenaltyD=0 ## DamageD=0 ## DrainD=0 ## LegacyD=0 ## TitleD=0;"]
[H: value = json.fromStrProp(Propertyname,"##")]
[R: value = json.get(value,"ProfS")]

femanon
Cave Troll
Posts: 95
Joined: Sat Jun 16, 2012 10:25 pm

Re: Retrieving individual variables from a list of nested ar

Post by femanon »

aliasmask wrote:Oops, wrong function:

Code: Select all

[H: Propertyname="AbilSTR= ## BaseS=0 ## EnhS=0 ## MoralS=0 ## AlchS=0 ## SizeS=0 ## SacrS=0 ## ProfS=0 ## InhS=0 ## RaceS=0 ## PenaltyS=0 ## DamageS=0 ## DrainS=0 ## LegacyS=0 ## TitleS=0; AbilDEX=BaseD=0 ## EnhD=0 ## MoralD=0 ## AlchD=0 ## SizeD=0 ## SacrD=0 ## ProfD=0 ## InhD=0 ## RaceD=0 ## PenaltyD=0 ## DamageD=0 ## DrainD=0 ## LegacyD=0 ## TitleD=0;"]
[H: value = json.fromStrProp(Propertyname,"##")]
[R: value = json.get(value,"ProfS")]

I'm getting the feeling you aren't hearing me, unless I am mistaken, this macroscript will not work outside of a macro, which makes it rather unworkable for me. I need this code to execute from within a property. in my experiance, assigning a variable a value and then calling it later doesn't work as it does not seem to save the variable. I also need it to differentiate between the two lists and select from one, rather than go over the entire list.

User avatar
aliasmask
Deity
Posts: 8692
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Retrieving individual variables from a list of nested ar

Post by aliasmask »

I put Propertyname in to a variable for demonstration. If it's in a token property already, then you don't have to have that line.

If you're going with a macro-less where you never access the variables directly, then you're just showing the variables in the stat sheet. Is that what you're talking about? Otherwise, what's the point of storing variables.

femanon
Cave Troll
Posts: 95
Joined: Sat Jun 16, 2012 10:25 pm

Re: Retrieving individual variables from a list of nested ar

Post by femanon »

aliasmask wrote:I put Propertyname in to a variable for demonstration. If it's in a token property already, then you don't have to have that line.

If you're going with a macro-less where you never access the variables directly, then you're just showing the variables in the stat sheet. Is that what you're talking about? Otherwise, what's the point of storing variables.

Variables can be placed in the stat sheet or propertylist that are drawn from other variables with for example, the getStrProp, or other basic property fields. These variables can be calculated to produce a value just like in regular macro script, for example. if you wanted to compute your strength based on the ammount of different variables, including conditions like fatigue, you could arrange them within mathematical logic.

The tools like Max and Min are really helpful to this. for AC Min can be used to decide between your armor dex limit and the ammount of dex you have. Max can be used to combine luck or morale bonuses from items, or enhancment bonuses from spells, to decide which of an identical bonus should apply (the greater bonus).

To make use of this, I plan to store variables twice in different properties, so that they may be easily edited in their lonesome, and then retrived, in this way, I don't have to worry about editing certain parts of Deflection=Max(item,spell,spell,spell,classfeature) when i edit with setstrprop, I can just edit the variable indirectly in another part of the database.

traditionally I use a battery of get and set str props, but this becomes a problem later because of the stack overflow being tripped by all the variables I use, which is why I'm trying to start stuffing these things into nested arrays, as retrieving them and storing them is much easier in macroscript in actual macros.

The advantages this offers is mostly based around being able to use loops more easily without becoming a slave to an index system where every variable must be assigned a number, arrays are also faster to be made into variables with a few functions, and by having them nested, I wont need a hundred different properties to store each array, as I am trying to do this while needing no changes needed from the host.

User avatar
aliasmask
Deity
Posts: 8692
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Retrieving individual variables from a list of nested ar

Post by aliasmask »

Take a look at [wfunc]varsFromStrProp[/wfunc]. This is one way to define many variables without a loop or many properties.

User avatar
wolph42
Deity
Posts: 9883
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Retrieving individual variables from a list of nested ar

Post by wolph42 »

if youre swinging that way I would reconsider your structure:

Code: Select all

Propertyname= 
AbilSTR=BaseS=0 ## EnhS=0 ## MoralS=0 ## AlchS=0 ## SizeS=0 ## SacrS=0 ## ProfS=0 ## InhS=0 ## RaceS=0 ## PenaltyS=0 ## DamageS=0 ## DrainS=0 ## LegacyS=0 ## TitleS=0; AbilDEX=BaseD=0 ## EnhD=0 ## MoralD=0 ## AlchD=0 ## SizeD=0 ## SacrD=0 ## ProfD=0 ## InhD=0 ## RaceD=0 ## PenaltyD=0 ## DamageD=0 ## DrainD=0 ## LegacyD=0 ## TitleD=0;

If you invent one specific letter for each variable like ProfS for strength and ProfD for dex then you can remove 'AbilSTR' and 'AbilDEX' and replace the entire property value with one big strprop:

Code: Select all

Propertyname= "BaseS=0 ;EnhS=0 ;MoralS=0 ;AlchS=0 ;SizeS=0 ;SacrS=0 ;ProfS=0 ;InhS=0 ;RaceS=0 ;PenaltyS=0 ;DamageS=0 ;DrainS=0 ;LegacyS=0 ;TitleS=0 ;BaseD=0 ;EnhD=0 ;MoralD=0 ;AlchD=0 ;SizeD=0 ;SacrD=0 ;ProfD=0 ;InhD=0 ;RaceD=0 ;PenaltyD=0 ;DamageD=0 ;DrainD=0 ;LegacyD=0 ;TitleD=0"


then when you use

Code: Select all

[varsFromStrprop(Propertyname)]

you have all variables defined in one go. I've benchmarked the function and its insanely fast. The fastest method to create a bunch of variables in one go.

femanon
Cave Troll
Posts: 95
Joined: Sat Jun 16, 2012 10:25 pm

Re: Retrieving individual variables from a list of nested ar

Post by femanon »

wolph42 wrote:if youre swinging that way I would reconsider your structure:

Code: Select all

Propertyname= 
AbilSTR=BaseS=0 ## EnhS=0 ## MoralS=0 ## AlchS=0 ## SizeS=0 ## SacrS=0 ## ProfS=0 ## InhS=0 ## RaceS=0 ## PenaltyS=0 ## DamageS=0 ## DrainS=0 ## LegacyS=0 ## TitleS=0; AbilDEX=BaseD=0 ## EnhD=0 ## MoralD=0 ## AlchD=0 ## SizeD=0 ## SacrD=0 ## ProfD=0 ## InhD=0 ## RaceD=0 ## PenaltyD=0 ## DamageD=0 ## DrainD=0 ## LegacyD=0 ## TitleD=0;

If you invent one specific letter for each variable like ProfS for strength and ProfD for dex then you can remove 'AbilSTR' and 'AbilDEX' and replace the entire property value with one big strprop:

Code: Select all

Propertyname= "BaseS=0 ;EnhS=0 ;MoralS=0 ;AlchS=0 ;SizeS=0 ;SacrS=0 ;ProfS=0 ;InhS=0 ;RaceS=0 ;PenaltyS=0 ;DamageS=0 ;DrainS=0 ;LegacyS=0 ;TitleS=0 ;BaseD=0 ;EnhD=0 ;MoralD=0 ;AlchD=0 ;SizeD=0 ;SacrD=0 ;ProfD=0 ;InhD=0 ;RaceD=0 ;PenaltyD=0 ;DamageD=0 ;DrainD=0 ;LegacyD=0 ;TitleD=0"


then when you use

Code: Select all

[varsFromStrprop(Propertyname)]

you have all variables defined in one go. I've benchmarked the function and its insanely fast. The fastest method to create a bunch of variables in one go.

I am already aware of varsfrom strprop. again you guys are completely misunderstanding what I'm saying here. if you don't think nesting is the right way to go about it that's great, but I told you guys specifically the issue I'm running into is getting my option to work in the property environment. Please address that issue.

secondly, if you DO suggest I do not use nested arrays, or that they wont work in the system, please explain how I should go about storing variables in a swift fashion after editing then, as while I can conceive of creating a loop with listreplace and strpropfromvars, I want to avoid tying every variable to an index number.

the current system I worked out is desirable because even if I have to use index, each variable list will have its own short index that wont affect any of the other indexes which means if I get caught flat footed and have to add a new variable, I dont have to go back and map out a new set of indexes for every loop I make, I just have to change the loops for the specific variable list. If the property list becomes one array instead of many, any change in that list can and will affect the index of every variable after it.

User avatar
wolph42
Deity
Posts: 9883
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Retrieving individual variables from a list of nested ar

Post by wolph42 »

Can you give us a very specific example of what you want to achieve? In terms of eg player a wants increase her strength with +1 while the property is embedded I the list... Probly not the right example but I'm asking for one. To directly answer your q yes you can use nested lists but you're also eluding me in what it is you wish to achieve.

femanon
Cave Troll
Posts: 95
Joined: Sat Jun 16, 2012 10:25 pm

Re: Retrieving individual variables from a list of nested ar

Post by femanon »

wolph42 wrote:Can you give us a very specific example of what you want to achieve? In terms of eg player a wants increase her strength with +1 while the property is embedded I the list... Probly not the right example but I'm asking for one. To directly answer your q yes you can use nested lists but you're also eluding me in what it is you wish to achieve.

the goal of the nested list is to serve two over all purposes. number one, to retrieve variables in a format clear of any mathematical notation, so that they can be used in mathematical formulae in a different property field, which will govern the variables and how they react in macros.


just for reference this is an example of what I am talking about, albiet it is not my code
STR Property field

Code: Select all

[r:STRbase + max(STRenh,BStrength) + STRluck + STRsac + STRpro + STRbonus + max(STRmoral, if(Enraged == 1, STRenrage, 0), Rage) + 2 * Enlarge - (getState("Exhausted") * 6) - (getState("Fatigued") * 2)]

These all pull from properties that exist, which I plan to instead use the nested arrays, the problem I am experiancing is finding a function or code that will call from the array instead of a property. Normally I use getstrprop, but this will now return a list and there is no way afaik to nest them without using a variable, which will afaik not function within the property environment, at least according to the tests I've ran.

The other goal of this is to make for ease of use in editing and storing variables in the macroscript I use in actual macro buttons. Calling an array and saving it within another array are fairly easy to do, and provide the added benefit that replacing articles within each array individually only requires indexing each nested array independantly, where indexing refers to keeping track of which variable of the array is associated with it's chronological position in the array, Doing this makes it easy to loop through and apply changes without the clunkyness of padding an index nor needing to surgically edit large portions of code for any future changes in the index.

The latter can easily be accomplished with the nested option I came up with, the problem is the former, calling individual variables to be used in formulae from a nested array in a property field. I'm not sure what deeper example I can give, the end user doesn't really need to mess with this stuff, preferably they will have access to changing the nested arrays individual variables from dialog boxes and macro script, but I can't commit to this method unless I know it will work so I haven't even begun to make any code that does that.

User avatar
wolph42
Deity
Posts: 9883
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Retrieving individual variables from a list of nested ar

Post by wolph42 »

man, in another discussion I'm having major trouble to convey a message which just doesn't comes accross. Its interesting sit on the other side, like in this case, as I REALLY have trouble 'getting' you.

but lets give it (another) shot. One step at a time
just for reference this is an example of what I am talking about, albiet it is not my code
STR Property field

Code: Select all

[r:STRbase + max(STRenh,BStrength) + STRluck + STRsac + STRpro + STRbonus + max(STRmoral, if(Enraged == 1, STRenrage, 0), Rage) + 2 * Enlarge - (getState("Exhausted") * 6) - (getState("Fatigued") * 2)]

These all pull from properties that exist, which I plan to instead use the nested arrays, the problem I am experiancing is finding a function or code that will call from the array instead of a property. Normally I use getstrprop, but this will now return a list and there is no way afaik to nest them without using a variable, which will afaik not function within the property environment, at least according to the tests I've ran.


What *I* gather from this is that the above STR property call existing properties directly, while *you* want to retrieve these variables from a nested array in another property
lets keep things REALLY simple:
you want this:
STR Property field

Code: Select all

[r:STRluck + STRsac]

while STRluck and STRsac are nested somewhere in an array in another property e.g.
another property on the token, lets call it stuffARRAY which contains (for example)

Code: Select all

AbilSTR=STRluck=0 ## STRsac=0; AbilDEX=DEXluck=0 ## DEXsac=0


is that correct? lets not go into the other goals, lets first try to understand eachother.

[spoiler=note to self]this works:
abilARRAY:Constitution=10 ;Dexterity=12
*calcProps:[h:varsFromStrprop(abilARRAY)]
*Constitution
*Dexterity[/spoiler]

User avatar
aliasmask
Deity
Posts: 8692
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Retrieving individual variables from a list of nested ar

Post by aliasmask »

My one rhetorical question is why are you making it harder than it should be. Use macros and use a lib token. If your goal is to have a complex set of abilities that can be dropped in to any campaign without GM intervention, then good luck to you. But I think we've answered the original question "Retrieving individual variables from a list of nested arrays". Perhaps the lingo is a barrier to us where a word you're saying isn't what we're interpreting. Variable, a property that stores a value. Array, a list of values. Nested arrays, arrays whose values are arrays. So, if I want to retrieve a value from a nested array, I need its location in the nested structure. Doing everything with in the token type properties.

number one, to retrieve variables in a format clear of any mathematical notation

There many methods of retrieving a variable. [wfunc]getProperty[/wfunc] is the most common method. I'm not sure what you mean by "clear of any mathematical notation. That's just a value. Even a string that looks like a formula is just a string until you do something with it.
, so that they can be used in mathematical formulae in a different property field, which will govern the variables and how they react in macros.

This is really not clear to me. But you have a formula in a property that references the other property above. This is very common, for example:

Token Properties:

Code: Select all

*Strength (STR): 15
StrB:[R: floor((Strength-10)/2)]



But what I'm getting from your previous posts is that you have a lot of variables to define and don't want to create a property for each, but still need to access the values. Access where, in other properties? Here's a stab in the dark at what I think you're talking about.

Token Properties:

Code: Select all

stats:Strength=10;Dexterity=10;Constitution=10;Intelligence=12;Wisdom=10;Charisma=10;
*bonuses:[H: varsFromStrProp(stats)][R: "StrB "+floor((Strength-10)/2)+", DexB "+floor((Dexterity-10)/2)+", ConB "+floor((Constitution-10)/2)+", IntB "+floor((Intelligence-10)/2)+", WisB "+floor((Wisdom-10)/2)+", ChaB "+floor((Charisma-10)/2)]

This just uses the data in stats, defines them in bonuses for use in setting the value of that property. bonuses is just text that lists what the bonuses are, but if I wanted to set those values in an array, then I would do this:

Code: Select all

stats:Strength=10;Dexterity=10;Constitution=10;Intelligence=12;Wisdom=10;Charisma=10;
bonuses:[H: varsFromStrProp(stats)][R: json.toStrProp(json.set("{}","StrB",floor((Strength-10)/2),"DexB",floor((Dexterity-10)/2),"ConB",floor((Constitution-10)/2)"IntB",floor((Intelligence-10)/2)"WisB",floor((Wisdom-10)/2)"ChaB",floor((Charisma-10)/2)))]

This creates a whole new set of variables based on the property above. But, there is one major problem. It doesn't calculate the variables unless you put * in front and then mouse over token. Then with more complicated formulas, you'll have to have varsFromStrProp all the data sets on that one line and it's really REALLY easy to cause some error popups that seems to be infinite. Putting all this junk on a token instead of in the properties is the way to go.

femanon
Cave Troll
Posts: 95
Joined: Sat Jun 16, 2012 10:25 pm

Re: Retrieving individual variables from a list of nested ar

Post by femanon »

wolph42 wrote:man, in another discussion I'm having major trouble to convey a message which just doesn't comes accross. Its interesting sit on the other side, like in this case, as I REALLY have trouble 'getting' you.

but lets give it (another) shot. One step at a time
just for reference this is an example of what I am talking about, albiet it is not my code
STR Property field

Code: Select all

[r:STRbase + max(STRenh,BStrength) + STRluck + STRsac + STRpro + STRbonus + max(STRmoral, if(Enraged == 1, STRenrage, 0), Rage) + 2 * Enlarge - (getState("Exhausted") * 6) - (getState("Fatigued") * 2)]

These all pull from properties that exist, which I plan to instead use the nested arrays, the problem I am experiancing is finding a function or code that will call from the array instead of a property. Normally I use getstrprop, but this will now return a list and there is no way afaik to nest them without using a variable, which will afaik not function within the property environment, at least according to the tests I've ran.


What *I* gather from this is that the above STR property call existing properties directly, while *you* want to retrieve these variables from a nested array in another property
lets keep things REALLY simple:
you want this:
STR Property field

Code: Select all

[r:STRluck + STRsac]

while STRluck and STRsac are nested somewhere in an array in another property e.g.
another property on the token, lets call it stuffARRAY which contains (for example)

Code: Select all

AbilSTR=STRluck=0 ## STRsac=0; AbilDEX=DEXluck=0 ## DEXsac=0


is that correct? lets not go into the other goals, lets first try to understand eachother.

[spoiler=note to self]this works:
abilARRAY:Constitution=10 ;Dexterity=12
*calcProps:[h:varsFromStrprop(abilARRAY)]
*Constitution
*Dexterity[/spoiler]

That is completely correct. this is exactly what I want to do.

Post Reply

Return to “Macros”