You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

CompuChip

Beginner

  • "CompuChip" started this thread

Posts: 2

Location: Ohio, USA

Occupation: IT

  • Send private message

1

Sunday, November 22nd 2015, 6:46pm

Both null and not null? Testing for the existence of a data element

I've managed to figure out how to provide a textbox on each scene in a tour. I've even made it dynamic by creating a correlation between scene names and my data fields:

Source code

1
2
3
4
5
6
7
8
<scene name="scene_01" ...
<scene name="scene_02" ...
<scene name="scene_03" ...

...

<data name="desc_scene_01">Scene 1.</data>
<data name="desc_scene_02">Scene 2.</data>


Not every scene has a description so for those scenes, I want to test for the existence of the data element and just hide the text layer. That is where I'm having a problem.

I can do this to get what the data elements should be IF they exist with no problem:

Source code

1
2
3
txtadd(dataName,'desc_',get(scene[get(xml.scene)].name));
txtadd(dataAssignName,'data:',get(dataName));
set(dataContent, get(data[get(dataName)].content));


I can even do a trace to see what the content of the field is and the trace returns null if the scene doesn't have a corresponding data element (such as scene_03 above). This returns null for scene_03...returns content for scenes 1 and 2.

Source code

1
trace(get(dataContent));


But, when I do this on the very next line it says, "not null"

Source code

1
if (get(dataContent) == null, trace('null'),trace('not null'));


HUH? How can get(dataContent) evaluate to null on one line and then when I do a comparison on the very next line and compare it to null, it evaluates to false?

Posts: 1,850

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

2

Sunday, November 22nd 2015, 7:58pm

Try == '' and or === ''
Also unless you plan to expand your data structure its simpler just to put the title in the scene tag itself

scene[get(xml.scene)].title
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

CompuChip

Beginner

  • "CompuChip" started this thread

Posts: 2

Location: Ohio, USA

Occupation: IT

  • Send private message

3

Monday, November 23rd 2015, 12:37am

I've tried the following:

Source code

1
2
3
4
5
if (get(dataContent) === 'null', trace('null'),trace('not null'));
if (get(dataContent) === null, trace('null'),trace('not null'));

if (get(dataContent) == 'null', trace('null'),trace('not null'));
if (get(dataContent) == null, trace('null'),trace('not null'));

The first two evaluate to null regardless of whether I have a data node, the second two evaluate to not null regardless.

I may wind up putting the call in the scene tag itself, but architecturally, I'm putting this information in an include file and trying to avoid messing with the generated main file as much as possible in case I ever want to regenerate a mass of files for some reason (possibly if there is a version upgrade or if I change my site concept). I'm hoping to write some tooling to help me in managing the site content and the less I need to touch generated code, the better (although I suppose I could just generate that page myself and overwrite the krpano xml files entirely).

The main reason though is that I've just started learning this tool. As a long-time geek, not understanding why something works the way it does bothers me as something like this could bite me down the road if the behavior is inexplicable to me.

4

Wednesday, December 2nd 2015, 11:34am

Hi,

the correct way for testing if a variable exists would be this: (not get() and no quotes):

Source code

1
2
if(variablename !== null, trace(the variable exists) );
if(variablename === null, trace(the variable does not exists) );


Best regards,
Klaus