the syntax. assign a value
-
-
Hi San,
Do you meanbutton.dog = 'labrador';
?
Tuur
-
Hi San,
Do you meanbutton.dog = 'labrador';
?
Tuur
Hi Tuur!
example test(screenshot, x, 50);
<action name="test" scope="local" args="name, atr, val" >
button = layer[*name];
button[*atr] = val;
</action>
I need to get
trace(layer[screenshot].x); // 50
-
<action name="bla" scope="local" args="n,a,v">
b = layer[*n];
b2 = 'b.'+a;
calc(*b2,v);
</action>or
<action name="bla" scope="local" args="n,a,v">
b='layer[*n].' + a;
calc(*b, v);
</action>
or perhaps<action name="bla" type="js">
<![CDATA[
let h = args[1];
let a = args[2];
let v = args[3];
let b = 'layer['+h+'].' + a;
krpano.set(b, v);
]]>
</action>And call: bla('screenshot', 'x',50);
..on holiday now.. should be good or close though.
Tuur -
-
should work, doesn't it ?
Nope!
Attribute between []..?Edit:
More sense would make:
bla('layer','screenshot', 'x',30);
<action name="bla" scope="local" args="t,n,a,v">
b=t+'[*n].' + a;
calc(*b, v);
</action>Then you can do a lot with just calling the 'bla' action
Tuur
-
yes, this is a simplified example and it doesn't make sense, but my code needs this mechanism itself.
button[*attr] = val; It doesn't work
b2 = 'b.'+a;
calc(*b2,v);It seems to be working, oddly enough
-
It's not odd!
You guys put the attribute in the place of the name.
bla('layer','screenshot', 'x',30);
<action name="bla" scope="local" args="t,n,a,v">
b=t+'[*n].' + a;
*b = v;
</action>Tuur
-
-
short excurse :
op = { attr: 5 }; // simple object with attribute
console.log(op.attr); // 5 (dot notation)
console.log(op["attr"]); // 5 (bracket notation, quotes needed)
....
maybe that works : button["*attr"] = val;
hm.. probably not, because "*attr" doesnt get resolved .-)
-
invalid array access!
-
short excurse :
op = { attr: 5 }; // simple object with attribute
console.log(op.attr); // 5 (dot notation)
console.log(op["attr"]); // 5 (bracket notation, quotes needed)
....
maybe that works : button["*attr"] = val;
hm.. probably not, because "*attr" doesnt get resolved .-)
yes, but it's js.
I wanted to understand how to write it in krpano
I tried button["*attr"] = val; and it doesn't work for me. -
button[get(attribute)] = value;
doesnt work because the quotes " are missing
button["*attr"] = val;
doesn't work because "*attr" is taken as string and doesn't get resolved by krpano
button[calc('"' + attribute + '"')] = value;
this should work, but is less elegant than tuurs solution
:)
-
-
<action name="bla" type="js">
<![CDATA[
let n = args[1];
let a = args[2];
let v = args[3];
let b = 'hotspot['+n+']';
krpano.set(b+'.' + a, v);
]]>
</action>I like eric's one ^ better though!
Tuur
-
Thank you all for your help!
but it's good when you understand them!
-
-
- Official Post
Hi,
here another possibility as one-liner:
The ('button.'+attribute) gets evaluated as expression and its result then is used as argument for the set() call.
Notes the other suggestions from above - using array indices [] for addressing attributes doesn't work in krpano action code, that's Javascript syntax.
Best regards,
Klaus -
Hi,
here another possibility as one-liner:
The ('button.'+attribute) gets evaluated as expression and its result then is used as argument for the set() call.
Notes the other suggestions from above - using array indices [] for addressing attributes doesn't work in krpano action code, that's Javascript syntax.
Best regards,
KlausHi,Klaus! Thank you for the information!
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!