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.

gabriel

Beginner

  • "gabriel" started this thread

Posts: 26

Location: Paris, France

Occupation: photographer

  • Send private message

1

Friday, January 1st 2016, 4:59pm

use trace content as a variable

Hi All,
happy new year!
i'm looking to use the trace content as a new variable for a if action, like in this exemple:

Source code

1
2
3
4
<action name="compare">
  set (A,false);
  if((text == "get(trace)"),set (A, true));
  if(A == true,...

Is there a way to remplace the sentence "get(trace)" by something who works ?
thank you.

Gabriel.

panomaster

Intermediate

Posts: 279

Location: Kobyłka, Poland

Occupation: Virtual Tours - Spherical Panoramas - Krpano developer

  • Send private message

2

Friday, January 1st 2016, 6:29pm

Every programming language have some restricted words that cannot be variable names eg. var is not a good name of variable in Javascript.

'Trace' is a name of KRPano built in function so that is also bad idea to name any variable in this way. Try to avoid creating variables which names can collide with names of KRPano functions and your own functions.

Also testing "get(trace)" in string is a little bit risky - I'm not sure if KRPano parser not evaluate this string as command get(trace).

gabriel

Beginner

  • "gabriel" started this thread

Posts: 26

Location: Paris, France

Occupation: photographer

  • Send private message

3

Friday, January 1st 2016, 7:32pm

Hi Panomaster, and thank you for your answer.
here are some explainations of what i'm looking to do :
i have a hotspot named "music" who play music while on over :

Source code

1
<hotspot name="music1" onover="playsound(bgsnd, 'url.mp3|alt_url.ogg', 0); check_decompte(); trace(hotspot[music1].name)" />

this hotspot is set to enabled="false", and is enabled="true" when he is at the middle of the screen. This is done by a other action based on getlooktodistance action.
In the same time the user can give the name of the music in a box, i use for that the plugin textinput.js
the action "compare" is called directly by the plugin and compare the answer of the user with the true name of the music.

Source code

1
<action name="comparekc">			set (A,false);				if((text == "right name of the music currenntly played"), set (A, true));				if(A == true,

Source code

1
<plugin name="inputtest" devices="html5"	type="container" url="textinput.js"		text=""		onchanged="txtadd(plugin[output].html,, get(text)); compare(); set(text,);"		enabled="true"/>

this works, but works also for all the hotspots, if they are at the middle of the screen or not.
What i want to do is a double condition : if the hotspot is at the middle of the screen And if the answer is correct, then is ok
the trace fonction for the hotspot works , the inputtest works too, what i want to do is to put them together in a double condition : if the hotspot is at the middle of the screen, and if the answer is correct, then do something.
thanks a lot for your help,
Gabriel.

panomaster

Intermediate

Posts: 279

Location: Kobyłka, Poland

Occupation: Virtual Tours - Spherical Panoramas - Krpano developer

  • Send private message

4

Friday, January 1st 2016, 8:41pm

Why don't you use logic operators in if statement?

if (testvalue1 AND testvalue2, ...);

gabriel

Beginner

  • "gabriel" started this thread

Posts: 26

Location: Paris, France

Occupation: photographer

  • Send private message

5

Friday, January 1st 2016, 9:24pm

It's what i want to do, but the value 2 who is working is "trace",
so the question is how to put the value of "trace" in a variable that i can put in the if condition.

6

Wednesday, January 6th 2016, 10:10am

Hi,

e.g. this way (when 'text' and 'trace' are variables):

Source code

1
2
3
set (A,false);
if(text === trace, set (A,true));
if(A == true,...


By using '===' instead of '==' the comparison is forced to assume that these are variables. When using '==' and the variable doesn't exits the comparison would assume that 'trace' is just a 'text'.

This behavior could be also generally disabled by enabling the 'strict' mode (version 1.19):
http://krpano.com/docu/xml/#krpano.strict

See also here the expressions documentation:
http://krpano.com/docu/actions/#expressions

And as panomaster already said try to avoid name-conflicts, but in this case it should also work this way...

Best regards,
Klaus

gabriel

Beginner

  • "gabriel" started this thread

Posts: 26

Location: Paris, France

Occupation: photographer

  • Send private message

7

Wednesday, January 6th 2016, 9:23pm

Hi Klaus,
and thank you for your answer who reassures me.
I'm beginer in Krpano, and everytime i finaly found a solution, most of the time helped by members ,
then i seen after that it was wrote in the documentation ...
Thanks for this elegant and subtile language.
Gabriel.