• Help me understand.

    I am having issues with using the switch command. I'm trying to get an icon (plugin[info]) to switch scale on multiple clicks. With the code below, it will switch from the original scale (0.5) to the first variable (1.0) on the first click. On the second click, it does not switch to the second variable.

    Another oddity, If I change ANY value - i.e. original scale value, switch command's first or second variable - the command does not work at all.

    Using krpano 1.0.8.15

  • Hi,

    With the code below, it will switch from the original scale (0.5) to the first variable (1.0) on the first click. On the second click, it does not switch to the second variable.

    And the scale value was not modified anywhere else?
    As long as the scale values are exactly 0.5 and 1.0, it should of course!

    Another oddity, If I change ANY value - i.e. original scale value, switch command's first or second variable - the command does not work at all.

    That's normal - the switch action will only switch step-by-step through the given values.
    When the current value isn't listed in the list of switch values, then nothing will be happen.

    Best regards,
    Klaus

  • That's normal - the switch action will only switch step-by-step through the given values.
    When the current value isn't listed in the list of switch values, then nothing will be happen.

    Your response here makes sense, and answers my second question.

    However, there is still an issue with switch command. When a switch command's variable is 1.0, the command stops functioning after 1.0 is called.

    This works:

    Code
    <plugin name="scale-work"	url="scale-work.jpg"	scale="0.5"	onclick="switch(scale, 0.5, 0.7, 1.5);"	/>

    This does not work:

    Code
    <plugin name="scale-nonwork"	url="scale-nonwork.jpg"	scale="0.5"	onclick="switch(scale, 0.5, 0.7, 1.0);"	/>


    I have created a test tour for you to view. I have examples of working and non-working plugins. To me, it seems that this a bug in the code. Please let me know what you find.

    Test Tour - Switch Command Test

    Thank you for the help, Klaus!

  • Hi,

    thanks - great example!

    The problem here is that the switch action is internally always comparing strings/texts (case-insensitive-strings).

    But the 'scale' and 'alpha' variables are Numberic variables and are only storing the value, so when setting the value to 1.0 and reading it out again later, it will become just '1' - and this '1' converted to a string will not match the '1.0' and therefore the switch stops there.

    I will think about an internal workaround for this case - maybe through detecting if the variables are numbers and then directly comparing the numbers...

    A workaround for now, would be to use an additional custom variable and modifying that through switch() and then to copy the result. These custom variables will be String variables and therefore not doing any type-conversion.

    e.g. see the 'newscale' variable in this example:

    Code
    <plugin name="scale-work" url="scale-nonwork.jpg" align="center" y="+100" scale="0.5" newscale="0.5" onclick="switch(newscale, 0.5, 0.7, 1.0); copy(scale,newscale);"/>

    Best regards,
    Klaus

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!