You are not logged in.

1

Tuesday, June 5th 2012, 4:12am

Operations on variables passed from js

Hello, I have a doubt since I need to do some simple operations on a variable that is passed from the js, ( viewer.addVariable("serial",1);)

I can get that variable by using the get action. So for example
showtext(get(serial),infostyle); effectively shows the 1 value on screen. Now what I want is to add a value to the serial variable...it could be done by using the add action
add(get(serial),1);
However it would not change the actual get(serial) value how could that?? The confusion is because the add function works over the variable that is passed as the first argument ( like by reference in programming languages). But by doing the last action nothing is changed, what I mean is that if I use the following code:

add(get(serial),1);
showtext(get(serial),infostyle);

1 it's shown on screen, and nothing changes that... is there something like local variables in krpano??? or how could I add a value to a global variable and then retrieve the changed value?.
Thanks a lot.

Posts: 1,850

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

2

Tuesday, June 5th 2012, 4:49am

Quoted

add(get(serial),1);
However it would not change the actual get(serial) value how could that?? The confusion is because the add function works over the variable that is passed as the first argument ( like by reference in programming languages). But by doing the last action nothing is changed, what I mean is that if I use the following code:


OK

viewer.addVariable("serial",1);
this would be nothing more than a string equaling 1

unless you do

var serial = 1;
in your js

viewer.addVariable("serial",serial);
to pass a real js variable into krpano.

if want to change the value of serial of your js you could do
js(setval(serial,2));

js only calls a function so we need one setup for us

javascript function
function setval(var) {
serial = var;
krpano.set("serial", serial);
}

and our js function updates the krpano value.

I have no idea what you are trying to do. So there are probably easier methods. But at least you can cross talk from krpano, to js and back again.

see here for more details.
http://krpano.com/docu/js/
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

3

Tuesday, June 5th 2012, 7:18am

Hi,

the get() is wrong here:
add(get(serial),1);
the add() action needs a variable name to know where to store the result,
and when using get(var) then only the content of the variable will be passed to the action,
(btw - the add() action is automatically getting the content from given variables)

e.g. when serial=1 then the code line from above will become to:

Source code

1
add(1,1)

and means:

Source code

1
1 = 1 + 1

which doesn't makes sense of course

correct would be just:

Source code

1
add(serial,1)

and means:

Source code

1
serial = get(serial) + 1

Source code

1
serial = 1 + 1


e.g. you could also use the 3-parameter syntax:

Source code

1
add(serial, get(serial), 1);

or

Source code

1
add(serial, serial, 1);

which will finally become

Source code

1
add(serial, 1, 1);

and means:

Source code

1
serial = 1 + 1


btw - here a very good and very well written tutorial from Pinsane/Steve about the krpano action:
A Tutorial on Krpano Action Arguments (pt 1)

best regards,
Klaus

Similar threads