I'm a beginner and have a question.
In the code below, thumb_static_group is output as "1, 1, 2" in a loop.
On top of that, "thumb_static_group is 1!" is not output even though "1" is specified in the conditional branch.
I don't understand this, please help me.
Conditional statement branching question
-
-
welcome wakaba :)
Codetrace("thumb_static_group=",thumb_static_group); // 1,1,2 if(thumb_static_group == 1, trace("whee"); );
first you do not need get in trace/debug/error, and you dont need it in expressions (if/calc)
and you must use == or ===, not EQ ... see here: https://krpano.com/docu/actions/#expressions
-
Thank you.
I made some code modifications as shown below with reference to the above, but the log output was "thumb_static_group=hotspot[group1].link1_group".Codetxtadd(thumb_static_group,'hotspot[%1].link', get(j),'_group'); trace("thumb_static_group=",thumb_static_group); if(thumb_static_group == '1', trace("Match"); , trace("Not matching"); );
-
well thumb_static_group will never be 1 with this code :)
you need to use if(j == 1, ...
-
Thank you.
I tried comparing by matching numbers, but all the results are "Not matching".
Even though there were matching numbers, it did not become a "Match".
Is there something I wrote wrong?Codetrace('groupNumber:',get(thumb_static_group)); trace('number:',j); if(j == thumb_static_group, trace("Match"); , trace("Not matching"); );
Below is the log.
-
yr problem is elsewhere... full code plz
('1' == 1 should eval as true i think)
-
Thank you.
The code in the entire XML is below.What is written in the hotspot tag is
link1_group="1"
link2_group="1"
link3_group="2"
However, this
The numerical value is obtained with get(thumb_static_group).
If this number is 1, an icon will be added above the first thumbnail.
In the above case, two icons will be added.
The second thumbnail has one icon.The code is a bit complicated, but here it is.
Code
Display More<hotspot name="group1" style="_staticgroups-modal" url="btn/swing_on.png" ath="-102" atv="22" scale="0.8" rotate="0" zoom="false" total="3" column="3" link1_thumb="panel01_thumb.jpg" link1="popup_10.jpg" link1_comment="TEST1" link1_icon="btn/10.png" link1_group="1" link2_thumb="panel01_thumb.jpg" link2="popup_11.jpg" link2_comment="TETS2" link2_icon="btn/11.png" link2_group="1" link3_thumb="panel02_thumb.jpg" link3="popup_12.jpg" link3_comment="TEST3" link3_icon="btn/12.png" link3_group="2" /> <action name="staticgroups-modal"> autorotation(false); set(idletime, 9999999999999); set(global.tmpfov, get(view.fov)); div(line_count, get(hotspot[%1].total), get(hotspot[%1].column)); Math.ceil(line_count); mul(lower_count, get(line_count), get(hotspot[%1].column)); sub(lower_count, get(hotspot[%1].total)); if(lower_count == 0, set(lower_count, get(hotspot[%1].column))); set(h_margin,10); set(v_margin,45); add(linkgroups_width,get(hotspot[%1].column),1); mul(linkgroups_width,get(h_margin)); mul(thumb_total_w,get(hotspot[%1].column),120); add(linkgroups_width,get(thumb_total_w)); add(linkgroups_height,get(line_count),1); mul(linkgroups_height,get(v_margin)); mul(thumb_total_h,get(line_count),80); add(linkgroups_height,get(thumb_total_h)); addlayer(%1); set(layer[%1].visible,true); set(layer[%1].alpha,0); set(layer[%1].type,container); set(layer[%1].bgcolor,0xFFFFFF); set(layer[%1].bgalpha,1); set(layer[%1].bgcapture,true); set(layer[%1].keep,false); set(layer[%1].align,center); set(layer[%1].width,get(linkgroups_width)); set(layer[%1].height,get(linkgroups_height)); set(layer[%1].x,0); set(layer[%1].y,-30); set(layer[%1].zorder,81); set(layer[%1].handcursor,false); set(layer[%1].onhover, autorotation(false);); addlayer(modal_x); set(layer[modal_x].type,container); set(layer[modal_x].bgcolor,0x000000); set(layer[modal_x].bgalpha,0.6); set(layer[modal_x].bgcapture,true); set(layer[modal_x].keep,false); set(layer[modal_x].align,center); set(layer[modal_x].width,get(stagewidth)); set(layer[modal_x].height,get(stageheight)); set(layer[modal_x].x,0); set(layer[modal_x].y,0); set(layer[modal_x].zorder,80); set(layer[modal_x].handcursor,true); set(layer[modal_x].arg_1, %1); set(layer[modal_x].onclick,close_linkgroups(%1);); set(layer[modal_x].onhover, autorotation(false);); addlayer(linkgroups_close_x); set(layer[linkgroups_close_x].url,btn/controls.png); set(layer[linkgroups_close_x].align,rightbottom); set(layer[linkgroups_close_x].parent,%1); set(layer[linkgroups_close_x].visible,false); set(layer[linkgroups_close_x].zorder,82); set(layer[linkgroups_close_x].arg_1, %1); set(layer[linkgroups_close_x].onclick,close_linkgroups(%1)); set(layer[linkgroups_close_x].onhover, autorotation(false);); set(link_base_y,get(h_margin)); build_link(%1,get(h_margin), get(v_margin), get(linkgroups_width)); staticgroups-modal_thumb(%1); if(hotspot[%1].zoom ,looktohotspot(%1);); tween(layer[%1].alpha|layer[%1].scale, 1|1, 0.5, default, set(layer[linkgroups_close_x].visible,true);); </action> <action name="staticgroups-modal_thumb"> if(%2 != NEXT, set(i, 0); set(j, 1);); if(i LT hotspot[%1].total, txtadd(thumb_txt,'link_txt',get(i)); txtadd(thumb_static,'link_thumb',get(i)); txtadd(thumb_static_url,'hotspot[%1].link', get(j),'_thumb'); txtadd(thumb_static_icon,'hotspot[%1].link', get(j),'_icon'); txtadd(thumb_static_group, 'hotspot[%1].link', get(j), '_group'); copy(thumb_static_url, get(thumb_static_url)); txtadd(thumb_static_url,'images/panel/',get(thumb_static_url)); txtadd(thumb_static_parent,%1,get(i)); addlayer(get(thumb_static)); set(layer[get(thumb_static)].url,get(thumb_static_url)); set(layer[get(thumb_static)].parent,get(thumb_static_parent)); set(layer[get(thumb_static)].align,lefttop); set(layer[get(thumb_static)].edge,lefttop); set(layer[get(thumb_static)].keep,false); set(layer[get(thumb_static)].zorder,90); set(layer[get(thumb_static)].width,114); set(layer[get(thumb_static)].height,60); set(layer[get(thumb_static)].onhover,thumb_base_hover(get(name))); set(layer[get(thumb_static)].onout,thumb_base_out(get(name))); set(layer[get(thumb_static)].x,3); set(layer[get(thumb_static)].y,3); set(layer[get(thumb_static)].onclick, staticgroups-modal_thumb-viewModal(%1, get(name))); txtadd(static_txt,'hotspot[%1].link',get(j),'_comment'); copy(static_txt,get(static_txt)); txtadd(thumb_static_txt,'[p]',get(thumb_static_txt),'[/p]'); addlayer(get(thumb_txt)); set(layer[get(thumb_txt)].keep,false); set(layer[get(thumb_txt)].url,%SWFPATH%/plugins/textfield.swf); set(layer[get(thumb_txt)].parent,get(thumb_static_parent)); set(layer[get(thumb_txt)].html,get(static_txt)); if(device.mobile, set(layer[get(thumb_txt)].css,data:thumb_text_css_mobile);, set(layer[get(thumb_txt)].css,data:thumb_text_css); ); set(layer[get(thumb_txt)].align,leftbottom); set(layer[get(thumb_txt)].edge,lefttop); set(layer[get(thumb_txt)].width,120); set(layer[get(thumb_txt)].height,get(v_margin)); set(layer[get(thumb_txt)].background,false); set(layer[get(thumb_txt)].selectable,false); set(layer[get(thumb_txt)].x,0); set(layer[get(thumb_txt)].y,-3); <!-- TEST --> trace('groupNumber:',get(thumb_static_group)); trace('number:',j); if(j == thumb_static_group, trace("Match"); , trace("Not matching"); ); <!-- TEST --> if(j == thumb_static_group, addlayer(get(thumb_static_icon)); set(layer[get(thumb_static_icon)].url,get(thumb_static_icon)); set(layer[get(thumb_static_icon)].parent,get(thumb_static_parent)); set(layer[get(thumb_static_icon)].align,lefttop); set(layer[get(thumb_static_icon)].edge,lefttop); set(layer[get(thumb_static_icon)].ke ep,false); set(layer[get(thumb_static_icon)].zorder,91); set(layer[get(thumb_static_icon)].width,20); set(layer[get(thumb_static_icon)].height,20); set(layer[get(thumb_static_icon)].x,3); set(layer[get(thumb_static_icon)].y,3); ); inc(i); inc(j); staticgroups-modal_thumb(%1,NEXT); ); </action>
-
I'm not sure, but I think you are comparing an "integer" to a "string".
set(j, 1), will set the value of j to 1 (as an integer, a numeric value)
but get(thumb_static_group) will be "1" (notice the quotes), which is a string (not a numeric value)
If you compare 1 to "1", they are different.
Best is to convert both to string or to ints, and then compare their value.
-
... this is really strange code ... ...
do not :
- use minus in an action name (or any name)
- make a loop like this and use i, j as global variables
-
Thank you.
It certainly depends on the comparison between integers and strings.
Below is the excerpted and modified code.
If you set it to an integer, it will all be "0" and the result will be "Not matching".
This is my first time dealing with krpano, so I'm a bit lost.
Code
Display Moretrace('thumb_static_group: ' , get(thumb_static_group)); trace('j: ', j); set(thumb_static_group_int, calc(int(get(thumb_static_group)))); set(j_int, calc(int(j))); trace('thumb_static_group_int: ', thumb_static_group_int); trace('j_int: ', j_int); if(thumb_static_group_int == j_int, trace("Match"); , trace("Not matching"); );
Code
Display MoreINFO: thumb_static_group: 1 INFO: j: 1INFO: thumb_static_group_int: 0 INFO: j_int: 1 INFO: Not matchingINFO: thumb_static_group: 1 INFO: j: 2 INFO: thumb_static_group_int: 0 INFO: j_int: 2INFO: Not matching INFO: thumb_static_group: 2 INFO: j: 3 INFO: thumb_static_group_int: 0 INFO: j_int: 3 INFO: Not matching
Also, this code is a modification of something inherited from its predecessor, so it doesn't mean that the whole thing is known.
I'm just trying to figure it out. -
i don't think it is about number and string
trace(calc("1" == 1)); // true !
this whole code is flawed.. see PM
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!