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:

    Code
    <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.

  • 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).

  • 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 :

    Code
    <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.

    Code
    <action name="comparekc">			set (A,false);				if((text == "right name of the music currenntly played"), set (A, true));				if(A == true,
    Code
    <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.

  • Hi,

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

    Code
    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):
    https://krpano.com/docu/xml/#krpano.strict

    See also here the expressions documentation:
    https://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

  • 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.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!