Sie sind nicht angemeldet.

harveydustin

Anfänger

  • »harveydustin« ist der Autor dieses Themas

Beiträge: 4

Wohnort: Raleigh NC

Beruf: Graphic Design, Photography

  • Nachricht senden

1

Mittwoch, 19. Dezember 2012, 18:55

Switch code issue

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

Quellcode

1
2
3
4
5
6
7
8
9
10
11
<plugin name="info"
url="info.png"
align="right"
edge="center"
x="250"
y="0"
scale="0.5"
zorder="5"
enabled="true"
onclick="switch(scale, 1.0, 0.5);"
/>

2

Donnerstag, 20. Dezember 2012, 11:01

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

harveydustin

Anfänger

  • »harveydustin« ist der Autor dieses Themas

Beiträge: 4

Wohnort: Raleigh NC

Beruf: Graphic Design, Photography

  • Nachricht senden

3

Freitag, 21. Dezember 2012, 17:25

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:

Quellcode

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


This does not work:

Quellcode

1
<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!

4

Samstag, 29. Dezember 2012, 13:50

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:

Quellcode

1
<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