0
Under review

Is there a way to name a preference through the use of a variable?

dpotter05 6 years ago updated 6 years ago 4
If I'm trying to create a preference named "mark" like this:

<action name="setMark">
<assign property="preference:mark" value="_next">
</action>

If I have a variable named _mark, is there a way for me to designate the name of the preference with the variable like this?

<action name="setMark">
<assign property="preference:[var:mark]" value="_next">
</action>
I've also tried these:

"preference:[var:mark]"

"preference:_mark"
Under review
As long as the var you are using exists then either option is possible. So you would need to assign your [var:mark] or path correctly from an object with _mark to ensure that the preference can find that value. 

My advice is in your setmark action to throw an alert tag at the top to make sure that your variable has a value before you assign it to the pref. 

<action name="setMark">
<alert message="VAR - [var:mark] VAR2 - _next"
<assign property="preference:[var:mark]" value="_next">
</action>
I have an alert tag showing me the variable is holding the right value but I've been unable to get a preference to update using either of these two methods.

<assign property="preferences:[var:mark]" value="next">

<assign property="preferences:_mark" value="next">

The only way I've been able to write to a preference is to name it explicitly like this:

<assign property="preferences:MARK001" value="_next">
Update!  Using the eval feature works.  In the code below, I start by setting the counter t 1, then cycle through all 173 preference by loading them into variables and then using them to assign an image source.


<assign property="var:markCount" value="1"/>
<loop lhs="[var:markCount]" operator="lte" rhs="173"> <assign property="[eval:'var:'+'MARK[var:markCount]']" value="[pref:MARK[var:markCount]]" /> <assign property="[eval:'object:MARK[var:markCount]'+'.source']" value="[eval:'like.'+'[var:MARK[var:markCount]]'+'.png']" /> <assign property="var:markCount" value="[eval: [var:markCount] + 1]"/> </loop>