Sie sind nicht angemeldet.

1

Dienstag, 5. Juni 2012, 04:12

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.

Beiträge: 1 857

Beruf: Virtual Tours - Photography - Krpano developer

  • Nachricht senden

2

Dienstag, 5. Juni 2012, 04:49

Zitat

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

Dienstag, 5. Juni 2012, 07:18

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:

Quellcode

1
add(1,1)

and means:

Quellcode

1
1 = 1 + 1

which doesn't makes sense of course

correct would be just:

Quellcode

1
add(serial,1)

and means:

Quellcode

1
serial = get(serial) + 1

Quellcode

1
serial = 1 + 1


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

Quellcode

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

or

Quellcode

1
add(serial, serial, 1);

which will finally become

Quellcode

1
add(serial, 1, 1);

and means:

Quellcode

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

Ähnliche Themen