Referencing Variable in javascript

Special forum to share and discuss skins for Pano2VR and Object2VR
Post Reply
PaulK
Posts: 64
Joined: Thu Apr 29, 2010 10:53 am

Tue Apr 28, 2020 1:43 pm

Hello all
I hope you are all keeping safe at this crazy time.
A quick question - what's the correct syntax to reference a variable in a javascript if/else statement?
i.e.
how do I reference 'variable' below

if(variable = "x"){
skin.container_1.zIndex = "0"}
else{
skin.container_1.zIndex = "-1"}

Thank you in advance.

Paul
User avatar
Hopki
Gnome
Posts: 10165
Joined: Thu Jan 10, 2008 3:16 pm
Location: Layer de la Haye, Essex UK
Contact:

Tue Apr 28, 2020 2:01 pm

Hi Paul,
Have you see this page: https://ggnome.com/doc/javascript-api/
It has examples as well as all the calls.
Regards,
Hopki
Garden Gnome Software Support
If you send an e-mail to support please send a link to the forum post for reference.
support@ggnome.com
https://ggnome.com/wiki/documentation/
PaulK
Posts: 64
Joined: Thu Apr 29, 2010 10:53 am

Tue Apr 28, 2020 2:28 pm

Thanks Hopki for the very quick reply

I didn't even know that page existed! Very useful.

So I assume then:

if(pano.getVariableValue(varName:myVar) = "x"){
skin.container_1.zIndex = "0"}
else{
skin.container_1.zIndex = "-1"}

Paul
PaulK
Posts: 64
Joined: Thu Apr 29, 2010 10:53 am

Mon May 04, 2020 2:01 pm

Hello all

Here's a problem I'm facing and I can't fathom out what's happening!:

Here's the scenario:
I've a stack of 3 images the z-index is set to default.
I've a button that when clicked sets a counter which increments by 1 until it reaches 3 then goes back to 0.
This number is stored in a variable (var1) default value = 0.
Dependent on the number returned by the var1 an image needs to have it's zIndex set.
I have have written javascript code that achieves this.

The sequence is as follows:

1. mouse click: add 1 to var1
2. mouse click : mod / 3 to var1
3. mouse click: go to url:

Code: Select all

javascript:
var cc = pano.getVariableValue("var1");
var zi0;
var zi1;
var zi2;
var zIndexString;

function setZindex(){
if (cc == 0){
zi0 = 3
zi1 = 2
zi2 = 1;
}
else if (cc == 1){
    zi0 = 1
    zi1 = 3
    zi2 = 2;
}
else if(cc == 2){
    zi0 = 2
    zi1 = 1
    zi2 = 3;
}
}
setZindex()

zIndexString = `javascript:skin._imageone.style.zIndex = "${zi0}";
skin._imagetwo.style.zIndex = "${zi1}";
skin._imagethree.style.zIndex = "${zi2}";`;
pano.setVariableValue("varzindexjs", `${zIndexString}`);

4. mouse click: go to url: $(*varzindexjs)

I would expect the various images z-index(es) to change when the button is clicked but alas it does not.

Here's the strange thing - if I copy the resultant string from the above function and paste it directly into the action 4 above (Mouse click: go to url) event it works perfectly!
The string returned by the function, when var1 = 1 for example, is:

javascript:skin._imageone.style.zIndex = "3";
skin._imagetwo.style.zIndex = "2";
skin._imagethree.style.zIndex = "1";

Am I missing something fundamental here ? I've been at this for days and can't get it to work!

Hoping a fresh pair of eyes will help!

Many thanks
Paul
PaulK
Posts: 64
Joined: Thu Apr 29, 2010 10:53 am

Wed May 06, 2020 2:11 pm

Can anyone help?
User avatar
Tony
Posts: 904
Joined: Mon Feb 15, 2010 6:54 am
Location: Adelaide, South Australia
Contact:

Wed May 06, 2020 3:17 pm

Hi,

Don't know if this helps or not.

In my skin, I have an element called 'blue' behind another element. To change its z-index I use an action: Mouse Click | Go to URL | javascript:skin._blue.style.zIndex = "0"; This brings it to the front. Another action: Mouse Click | Go to URL | javascript:skin._blue.style.zIndex = "3"; sends it to the back.

https://p2vr.s3-ap-southeast-2.amazonaw ... index.html

TONY
Tony Redhead | Panoramic Photographer | mobile: +61438501002 | website: http://tonyredhead.com - http://redsquare.com | roundme: http://round.me/@tonyredhead | instagram: https://www.instagram.com/tonyredhead/
PaulK
Posts: 64
Joined: Thu Apr 29, 2010 10:53 am

Thu May 07, 2020 12:56 pm

Thanks Tony

I'm deep in javascript code at the mo - some interesting issues arising. I'll report back to the forum when I've come up with a answer!
Many thanks for your reply btw.
Paul
Post Reply