Conditional statement branching question

  • 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.


    Code
    trace(get(thumb_static_group)); <!-- 1,1,2 -->
    if(get(thumb_static_group) EQ 1,
        trace("thumb_static_group is 1!");
    );

    Edited once, last by wakaba-kks: trace(get(thumb_static_group)); <!-- 1,1,2 --> It seems that the above code is somehow a string. How can I turn this into numbers? An error occurred with number. (May 29, 2024 at 8:57 AM).

  • welcome wakaba :)

    Code
    trace("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".


    Code
    txtadd(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");
    );


    Code
    INFO: thumb_static_group=hotspot[group1].link1_group
    INFO: Not matching
    INFO: thumb_static_group=hotspot[group1].link2_group
    INFO: Not matching
    INFO: thumb_static_group=hotspot[group1].link3_group
    INFO: Not matching
  • 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?


    Code
    trace('groupNumber:',get(thumb_static_group));
    trace('number:',j);
    if(j == thumb_static_group,
    	trace("Match");
    	,
    	trace("Not matching");
    );


    Below is the log.

    Code
    INFO: groupNumber:1
    INFO: number:1
    INFO: Not matching
    INFO: groupNumber:1
    INFO: number:2
    INFO: Not matching
    INFO: groupNumber:2
    INFO: number:3
    INFO: Not matching
  • 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.


    Edited once, last by wakaba-kks: <style name="_staticgroups-modal" onout="autorotation(true);" onclick="staticgroups-modal(get(name))" /> (May 29, 2024 at 11:53 AM).

  • 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.

  • 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.




    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.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!