|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
<onstart="test-dereferencing(2,'spot-three')" />
<testarray>
<point name="one" />
<point name="two" />
<point name="three" />
<spot name="spot-one" x="1" />
<spot name="spot-two" x="2" />
<spot name="spot-three" x="3" />
</testarray>
<action name="test-dereferencing">
set(i,"2");
set(%3,"2");
set(tmpname,'spot-three');
trace(" ");
trace('i is ',i, ' testarry.point[i] is ', testarray.point[i].name);
trace('i is ',i, ' testarry.point[i] is ', testarray.point[get(i)].name);
trace('i is ',i, ' testarry.point[i] is ', get(testarray.point[get(i)].name));
trace('i is ',i, ' testarry.point[i] is ', get(testarray.point[i].name));
trace(" ");
trace('arg1 is ',%1, ' testarry.point[arg1] is ', testarray.point[%1].name);
trace('arg1 is ',%1, ' testarry.point[arg1] is ', testarray.point[get(%1)].name);
trace('arg1 is ',%1, ' testarry.point[arg1] is ', get(testarray.point[get(%1)].name));
trace('arg1 is ',%1, ' testarry.point[arg1] is ', get(testarray.point[%1].name));
trace(" ");
trace('arg3 is ',%3, ' testarry.point[arg3] is ', testarray.point[%3].name);
trace('arg3 is ',%3, ' testarry.point[arg3] is ', testarray.point[get(%3)].name);
trace('arg3 is ',%3, ' testarry.point[arg3] is ', get(testarray.point[get(%3)].name));
trace('arg3 is ',%3, ' testarry.point[arg3] is ', get(testarray.point[%3].name));
trace(" ");
trace('arg2 is ',%2, ' testarry.spot[arg2] is ', testarray.spot[%2].x);
trace('arg2 is ',%2, ' testarry.spot[arg2] is ', testarray.spot[get(%2)].x);
trace('arg2 is ',%2, ' testarry.spot[arg2] is ', get(testarray.spot[get(%2)].x));
trace('arg2 is ',%2, ' testarry.spot[arg2] is ', get(testarray.spot[%2].x));
trace(" ");
trace('tmpname is ',tmpname, ' testarry.spot[tmpname] is ', testarray.spot[tmpname].x);
trace('tmpname is ',tmpname, ' testarry.spot[tmpname] is ', testarray.spot[get(tmpname)].x);
trace('tmpname is ',tmpname, ' testarry.spot[tmpname] is ', get(testarray.spot[get(tmpname)].x));
trace('tmpname is ',tmpname, ' testarry.spot[tmpname] is ', get(testarray.spot[tmpname].x));
trace(" ");
trace('dereference-this(get(tmpname))');
dereference-this(get(tmpname));
trace(" ");
txtadd(newname,'spot-',testarray.point[%1].name);
trace(newname);
txtadd(newname,'spot-',get(testarray.point[%1].name));
trace(newname);
trace('newname is ',newname, ' testarry.spot[newname] is ', testarray.spot[newname].x);
trace('newname is ',newname, ' testarry.spot[newname] is ', testarray.spot[get(newname)].x);
trace('newname is ',newname, ' testarry.spot[newname] is ', get(testarray.spot[get(newname)].x));
trace('newname is ',newname, ' testarry.spot[newname] is ', get(testarray.spot[newname].x));
trace(" ");
dereference-this(get(newname));
</action>
<action name="dereference-this">
trace('arg1 is ',%1, ' testarry.spot[%1] is ', testarray.spot[%1].x);
trace('arg1 is ',%1, ' testarry.spot[%1] is ', testarray.spot[get(%1)].x);
trace('arg1 is ',%1, ' testarry.spot[%1] is ', get(testarray.spot[get(%1)].x));
trace('arg1 is ',%1, ' testarry.spot[%1] is ', get(testarray.spot[%1].x));
</action>
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
INFO: i is 2 testarry.point[i] is testarray.point[i].name INFO: i is 2 testarry.point[i] is testarray.point[get(i)].name INFO: i is 2 testarry.point[i] is 2 INFO: i is 2 testarry.point[i] is 2 INFO: INFO: arg1 is 2 testarry.point[arg1] is three INFO: arg1 is 2 testarry.point[arg1] is testarray.point[get(2)].name INFO: arg1 is 2 testarry.point[arg1] is 2 INFO: arg1 is 2 testarry.point[arg1] is three INFO: INFO: arg3 is 2 testarry.point[arg3] is testarray.point[null].name INFO: arg3 is 2 testarry.point[arg3] is testarray.point[get(null)].name INFO: arg3 is 2 testarry.point[arg3] is 2 INFO: arg3 is 2 testarry.point[arg3] is 2 INFO: INFO: arg2 is spot-three testarry.spot[arg2] is 3 INFO: arg2 is spot-three testarry.spot[arg2] is testarray.spot[get(spot-three)].x INFO: arg2 is spot-three testarry.spot[arg2] is 2 INFO: arg2 is spot-three testarry.spot[arg2] is 3 INFO: INFO: tmpname is spot-three testarry.spot[tmpname] is testarray.spot[tmpname].x INFO: tmpname is spot-three testarry.spot[tmpname] is testarray.spot[get(tmpname)].x INFO: tmpname is spot-three testarry.spot[tmpname] is 2 INFO: tmpname is spot-three testarry.spot[tmpname] is 2 INFO: INFO: dereference-this(get(tmpname)) INFO: arg1 is spot-three testarry.spot[spot-three] is 3 INFO: arg1 is spot-three testarry.spot[spot-three] is testarray.spot[get(spot-three)].x INFO: arg1 is spot-three testarry.spot[spot-three] is 2 INFO: arg1 is spot-three testarry.spot[spot-three] is 3 INFO: INFO: spot-testarray.point[2].name INFO: spot-three INFO: newname is spot-three testarry.spot[newname] is testarray.spot[newname].x INFO: newname is spot-three testarry.spot[newname] is testarray.spot[get(newname)].x INFO: newname is spot-three testarry.spot[newname] is 2 INFO: newname is spot-three testarry.spot[newname] is 2 INFO: INFO: arg1 is spot-three testarry.spot[spot-three] is 3 INFO: arg1 is spot-three testarry.spot[spot-three] is testarray.spot[get(spot-three)].x INFO: arg1 is spot-three testarry.spot[spot-three] is 2 INFO: arg1 is spot-three testarry.spot[spot-three] is 3 |
|
|
Quellcode |
1 |
set(%3,"2"); |
|
|
Quellcode |
1 |
set(null,"2"); |
|
|
Quellcode |
1 |
trace('%3 ',%3);
|
|
|
Quellcode |
1 |
INFO: null 2 |
|
|
Quellcode |
1 2 |
trace('i is ',i, ' testarry.point[i] is ', get(testarray.point[get(i)].name));
trace('i is ',i, ' testarry.point[i] is ', get(testarray.point[i].name));
|
|
|
Quellcode |
1 2 |
INFO: i is 2 testarry.point[i] is 2 INFO: i is 2 testarry.point[i] is 2 |
|
|
Quellcode |
1 |
testarray.point[get(i)].name |
|
|
Quellcode |
1 |
testarray.point[i].name |
|
|
Quellcode |
1 2 |
get(testarray.point[get(i)].name) get(testarray.point[i].name) |
|
|
Quellcode |
1 2 3 |
txtadd(newname,'spot-',get(testarray.point[%1].name));
trace(newname);
trace('newname is ',newname, ' testarry.spot[newname] is ', testarray.spot[newname].x);
|
|
|
Quellcode |
1 2 3 4 5 |
dereference-this(get(newname));
<action name="dereference-this">
trace('arg1 is ',%1, ' testarry.spot[%1] is ', testarray.spot[%1].x);
</action>
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<mappoints>
<stuff name="one" />
<stuff name="two" />
</mappoints>
<plugin name="loc-one" />
<plugin name="loc-two" />
<action name="scale-stuff">
foreach(mappoints.stuff,i,
scale2(get(i));
);
</action>
<action name="scale2">
txtadd(tmpname,'loc-',get(mappoints.stuff[%1].name));
do-scale-stuff(get(tmpname));
</action>
<action name="do-scale-stuff">
switch(plugin[%1].destscale,1,0.3);
tween(plugin[%1].scale,$destscale);
</action>
|
|
|
Quellcode |
1 2 3 4 5 6 7 |
<action name="scale-stuff">
foreach(mappoints.stuff,i,
txtadd(tmpname,'loc-',get(mappoints.stuff[i].name));
switch(plugin[tmpname].destscale,1,0.3);
tween(plugin[tmpname].scale,$destscale);
);
</action>
|
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »hitodenashi« (16. März 2010, 06:17)
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<krpano version="1.0.8" onstart="test-dereferencing()" >
<testarray>
<point name="one" />
<point name="two" />
<point name="three" />
<spot name="spot-one" x="1" />
<spot name="spot-two" x="2" />
<spot name="spot-three" x="3" />
</testarray>
<action name="trace_testarray_point">
trace("testarray point %1 =",testarray.point[%1].name);
</action>
<action name="test-dereferencing">
set(i,0);
trace_testarray_point(get(i));
inc(i);
trace_testarray_point(get(i));
inc(i);
trace_testarray_point(get(i));
</action>
</krpano>
|
|
|
Quellcode |
1 |
testarray.point[0] |
|
|
Quellcode |
1 |
testarray.point[%1] |
|
|
Quellcode |
1 |
testarray.point[i].name |
|
|
Quellcode |
1 |
testarray.point[get(i)].name |
|
|
Quellcode |
1 |
trace(testarray.point[%1].name); |
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<krpano version="1.0.8" onstart="test-dereferencing()" >
<testarray>
<point name="one" />
<point name="two" />
<point name="three" />
<spot name="spot-one" x="1" />
<spot name="spot-two" x="2" />
<spot name="spot-three" x="3" />
</testarray>
<action name="trace_testarray_point">
trace("testarray point %1 =",testarray.point[%1].name);
</action>
<action name="test-dereferencing">
set(i,0);
trace_testarray_point(get(i));
inc(i);
trace_testarray_point(get(i));
inc(i);
trace_testarray_point(get(i));
inc(i);
trace_testarray_point(get(i));
</action>
</krpano>
|
Zitat
INFO: testarray point 0 =one
INFO: testarray point 1 =two
INFO: testarray point 2 =three
INFO: testarray point 3 =testarray.point[3]
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<krpano version="1.0.8" onstart="test-dereferencing()" >
<action name="trace_action">
trace("%1%2%3%4%5%6");
</action>
<action name="test-dereferencing">
set(i,0);
set(j,i);<!--note this sets j to the string "i"-->
set(k,get(i));
trace("i=",i," j=",j," k=",k);
trace_action("i=",i," j=",j," k=",k);
trace(" get(i)=",get(i)," get(j)=",get(j)," get(k)=",get(k));
trace_action(" get(i)=",get(i)," get(j)=",get(j)," get(k)=",get(k));
</action>
</krpano>
|
Zitat
INFO: i=0 j=i k=0
INFO: i=i j=j k=k
INFO: get(i)=0 get(j)=0 get(k)=0
INFO: get(i)=0 get(j)=i get(k)=0
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »pinsane« (16. März 2010, 07:01)
Seems as though % variables are not treated the same as regular ones?
It works, but it makes no sense? Maybe I'm approaching it from the wrong angle?
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<krpano version="1.0.8" onstart="why_not_something_like_this()" > <mappoints> <stuff name="one" /> <stuff name="two" /> </mappoints> <plugin name="loc-one" /> <plugin name="loc-two" /> <action name="why_not_something_like_this"> foreach(mappoints.stuff,i, txtadd(tmp,'txtadd(tmpname,"loc-",get(mappoints.stuff[',get(i),'].name));'); eval_str(get(tmp)); txtadd(tmp,' switch(plugin[',get(tmpname),'].destscale,1,0.3); tween(plugin[',get(tmpname),'].scale,$destscale); '); eval_str(get(tmp)); ); </action> <!-- _eval_action private function to execute eval action --> <action name="_eval_action"> trace("Error in eval: push/pop stack corrupted"); <!-- this line should never execute --> </action> <!-- eval_str(evalstr.str); accepts a single string of action[s] which are executing in a blocking manner--> <action name="eval_str"> <!--evalstr.str--> push(action[_eval_action].content); set(action[_eval_action].content,%1); _eval_action(%2,%3,%4,%5,%6,%7,%8,%9); pop(action[_eval_action]content); </action> <!-- _foreach_action private function to execute foreach loop body action --> <action name="_foreach_action"> trace("Error in foreach loop: push/pop stack corrupted"); <!-- this line should never execute --> </action> <!-- foreach <objectid> <index.str> <body.str> foreach loop function which iterates the action across each of the objects--> <action name="foreach"> <!--objectid.str,index.str,body.str--> sub(%2,%1.count,1); push(action[_foreach_action].content); set(action[_foreach_action].content,"if(%2 GE 0,%3;dec(%2);_foreach_action(););"); _foreach_action(); pop(action[_foreach_action].content); </action> </krpano> |
Also what's the deal with the $ variables?
I also learned that using 'set(x,"0")' makes a global variable x. Any way to make it local variables?
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 |
<action name="scaler">
foreach(mappoints.stuff,i,
txtadd(action[scaler].tmp,'txtadd(action[scaler].tmpname,"loc-",get(mappoints.stuff[',get(i),'].name));');
eval_str(get(action[scaler].tmp));
txtadd(action[scaler].tmp,'
switch(plugin[',get(action[scaler].tmpname),'].destscale,1,0.3);
tween(plugin[',get(action[scaler].tmpname),'].scale,$destscale);
');
eval_str(get(action[scaler].tmp));
);
</action>
|
Zitat von »pinsane«
Zitat
Quoted from "hitodenashi"
It works, but it makes no sense? Maybe I'm approaching it from the wrong angle?
Actually, you're using the most readable approach. It works because you are evaluating the variable and then passing it through an argument where it is substituted into the square brackets. It's the most straightforward method.
|
|
Quellcode |
1 2 3 |
<mapthings> <floor name="2nd" /> </mapthings> |
|
|
Quellcode |
1 2 3 4 5 6 |
foreach(things,i,scale-things(get(i))); is a no-go, but foreach(things,i,scalethings(get(i))); is ok. foreach(things,i,do-scale-things(get(i))); is ok. |
I was on the verge of just dropping krpano and doing something easier, like debugging obfuscated perl.![]()
BTW, I propose a new attribute/pragma in the krpano node: scripting="sane" which drops all the nasty backward compatibility.
Having node names start with numbers is a bad idea:
![]()
Quellcode
1 2 3 4 5 6 foreach(things,i,scale-things(get(i))); is a no-go, but foreach(things,i,scalethings(get(i))); is ok. foreach(things,i,do-scale-things(get(i))); is ok.
WTF?
foreach(things,i,scale-things(get(i))) works but scale-things() gets passed a null?
Thanks hitodenashi, I laughed out loud when reading this. I should know better than to read this board when eating breakfast. Anyone know how to get Count Chocula off a computer monitor?
foreach(things,i,scale-things(get(i))); works for me. Can you post a complete example? scale-things() should pass a null to all %# arguments.
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<action name="hide-this"> if(%1 == null, derefthis(%0,get(name)), set(plugin[%1].enabled,false); tween(plugin[%1].alpha,0,0.3,null,set(plugin[%1].visible,false)); tween(plugin[%1].textblur,20,0.3); tween(plugin[%1].blur,20,0.3); ); </action> <!-- derefthis(caller,original-caller) --> <action name="derefthis"> action(%1,%2); </action> |
OTOH I was happy with this little thing:
![]()
Quellcode
1 2 3 4 5 6 7 8 9 10 11 12 13 <action name="hide-this"> if(%1 == null, derefthis(%0,get(name)), set(plugin[%1].enabled,false); tween(plugin[%1].alpha,0,0.3,null,set(plugin[%1].visible,false)); tween(plugin[%1].textblur,20,0.3); tween(plugin[%1].blur,20,0.3); ); </action> <!-- derefthis(caller,original-caller) --> <action name="derefthis"> action(%1,%2); </action>
Now I can have one action for all plugins :)


yes, get() would be probably more logically
I will add it in one of the next releases
...
have already added (in the next release) the possibility for using %10-%99