why are allmost all languages messed up in krpano and variable interaction

  • Hi,


    I'm working with pano-names (Pano_001,Pano_002,Pano_003...) and index-names (Kantine, labratory, classroom...)

    I want to get a index name in the html of a textfield by giving in a pano-name, i tried to make some variables in a style tag:

    Code
    <style name="PANONAMES"
    Pano_001index="Kantine"
    Pano_002index="Labratory"
    Pano_003index="classroom"
    </style>


    and then let the action pass thrue the variable indexname to the html of a textfield, but the problem is, i will get "get(style[PANONAMES].%1index)" as htmltext because i placed it between [p] and [/p].


    Code
    <plugin name="indextext" url="Plugins/textfield.swf" css="p{font-size:14;font-family:arial;}" />
     
    <action name="indextext">
    set(plugin[textfield].html,[p]get(style[PANONAMES].%1index)[/p])
    </action>


    i've tried to add the 2 p's and my code in a string with txtadd, but it doesnt work.


    Isn't there a way of making your one variables and being able to return them in a action, like:

    Code
    set(mynumber,squaremynumber(%1))
     
    <action name="squaremynumber">
    return(mult(%1,%1))
    </action>


    any ideas?


    Declan *smile*

  • Hello Declan,

    I agree that variable dereferencing, particularly when variables are used as indices, is one of the more confusing aspects of the krpano action language. I think Klaus is battling backwards compatibility where he needs to support unquoted strings along with variable names. I wish that he could provide a dereferencing mechanism that was similar to the way arguments work. Arguments seem to be substituted into your code very early in the parsing phase. Perhaps something like a @(varname) would be useful and probably wouldn't break too many legacy unquoted strings.

    But I digress. Here is a modified version of your xml which seems to work on version 1.0.8 beta9:


    I'm using txtadd to construct the string and then insert it into the textfield.

    May I humbly make a programming suggestion? You are using strings (which happen to be numbers) as indicies for your panos. Instead, why not actually use numbers to index your panos by empoying the following technique:


    Klaus has cleverly implemented a powerful array capability that can be used for both numerically indexed arrays and associative arrays (addressing by name). You'll note that in the following example the style node has been rewritten and the names have been placed into new nodes called pano nodes. These pano nodes are addressible via a number (style[PANONAMES].pano[1].name is "Labratory") but also can be accessed by name. Note that the pano node us user defined, it is not a standard krpano node name; we could have easily called them declan nodes instead!

    This is valuable because it separates your tour-dependent data from your code. You can change the names in one location rather than having the names sprinkled throughout your action code. You can write general-purpose actions, which can be used in multiple tours.

    for example:

    Note that all sorts of information can be stored here, and this minimizes the amount of tour dependent information (such as names) that are hardcoded into your actions. Note also that using this technique gives you a tremendous amount of programming power, because you can access the information with a numeric variable and even loop over all of your panos:

    Note that you can now add or change caption descriptions in the style node and the action doesn't have to change. You can even add or delete panos (by adding or deleting pano nodes in the style section) and the action continues to work.

    Hope this helps!

    steve

    Edited 2 times, last by pinsane (February 28, 2010 at 7:31 PM).

  • Thanks for the reply!

    I can see almost everything is possible with krpano but sometimes seeing the way the code works is the difficult part... I'm used to C# and other coding languages...

    I think i'm going to have to rewrite my code to make it more dynamically and more efficient.

    Thanks for all the help Steve!

    Declan *smile*

  • Hi, I'm trying to use that array possibility within style nodes, but i want the counting to start at 1 instead of 0. This is what i did:

    Code
    <style name="PANONAMES" >
    	<pano name="Kantine" caption="This is the kantine where grey food is served"/>
    	<pano name="Labratory" caption="This is the labratory where we perform evil experiments"/>
    	<pano name="classroom" caption="This is the classroom where we catch up on our sleep"/>
    </style>

    and

    Code
    <action name="IndexText">
    	add(VAR_num,%1,1);
    	txtadd(VAR_txt,"[p]",get(style[DATA].pano[get(VAR_num)].caption),"[/p]");
    	set(plugin[IndexText].html,get(VAR_txt));
    	set(plugin[IndexText].effect,glow(0x000000,0.7,4,2));
    	</action>

    But this doesn't work: NULL, the problem lies at the get(VAR_num)
    Any ideas?


    Declan

  • Hi Declan,


    Hi, I'm trying to use that array possibility within style nodes, but i want the counting to start at 1 instead of 0.

    How very Fortran of you. *smile* One easy way to do this is to add a dummy pano which will take the 0 position:

    Code
    <style name="PANONAMES" >
    	<pano name="Dummy" caption="This is the index zero entry which should never be accessed" />
    	<pano name="Kantine" caption="This is the kantine where grey food is served"/>
    	<pano name="Labratory" caption="This is the labratory where we perform evil experiments"/>
    	<pano name="classroom" caption="This is the classroom where we catch up on our sleep"/>
    </style>

    While this will work, let me encourage you to embrace your inner programmer and use the more modern indexing method that starts with 0. *wink*

    Code
    <action name="IndexText">
    	add(VAR_num,%1,1);
    	txtadd(VAR_txt,"[p]",get(style[DATA].pano[get(VAR_num)].caption),"[/p]");
    	set(plugin[IndexText].html,get(VAR_txt));
    	set(plugin[IndexText].effect,glow(0x000000,0.7,4,2));
    	</action>

    But this doesn't work: NULL, the problem lies at the get(VAR_num)
    Any ideas?
    Declan

    It doesn't work for two reasons.
    1) because you need to reference style[PANONAMES], not style[DATA]
    2) krpano's action language does not currently allow you to use the get() function as an index. What you can do is use an argument (such as %1).

    Okay, if you use the dummy method described above then the code can be written as:


    This is a simple solution that starts addressing at 1 (because the first pano is always ignored).

    Alternatively, if you're using krpano 1.0.8 beta 9 you can use klaus's new method of dereferencing a simple global variable. Here we'll use your original code with a couple of small modifications (including the correction where you must subtract rather than add one):


    By the way, there's really no need to use the style tag. you can simplify your code a bit by simply using the panos without the style:

    Hope this helps!

    steve

  • Quote

    1) because you need to reference style[PANONAMES], not style[DATA]


    Sorry, my fault. I copied my original code where i use DATA instead of PANONAMES

    Quote


    2) krpano's action language does not currently allow you to use the get() function as an index. What you can do is use an argument (such as %1).


    So you mean i cant use get() in an array index, what is the difference between get() and % ? (variable/argument)
    But could i do this too?

    Code
    set(plugin[IndexText].html,%VAR_txt); 
    
    
    instead of 
    
    
    set(plugin[IndexText].html,get(VAR_txt));


    It works now, thanks!

    I'm now trying to define everything in a TourData node:

    Code
    <TourData>
    	<pano name="Kantine" caption="This is the kantine where grey food is served"/>
    		<hotspot 	ath="170"	atv="20"	target="003" />
    	<pano name="Labratory" caption="This is the labratory where we perform evil experiments"/>
    	<pano name="classroom" caption="This is the classroom where we catch up on our sleep"/>
    </TourData>


    I'm trying to make pano's and hotspots dynamically, because most of the settings are the same for all pano's, and it could be much more efficient to do everything dynamically. (i've got like 30+ pano's....)
    so i want to make a loop which repeats exactly pano.count times. And automatically make new scenes.
    And the same thing for the hotspots.

    But i don't now to make the scenes this way, maybe you know?

    Declan *smile*

    Edited 3 times, last by rctdeclan (April 11, 2010 at 1:12 PM).

  • Hi Steve,

    thanks, great explanation! *wink*

    just some short news for the next release about this topic:
    - using get() inside array indices's will be possible (e.g. array[get(var)])
    - and it will be also possible to use full paths there (e.g. array[get(node[name].var)])


    Quote

    set(plugin[textfield].html,[p]get(style[PANONAMES].%1index)[/p])
    i've tried to add the 2 p's and my code in a string with txtadd, but it doesnt work.

    the get() function is a very special one, can be only used for a single parameter
    when calling an action, and it all it does is to resolve the given variable before
    calling the action,

    it you want to combine texts you need to use the txtadd() action,
    e.g.
    [code]txtadd(plugin[textfield].html,'[p]',get(style[PANONAMES].%1index),'[/p]');

    Quote

    Isn't there a way of making your one variables and being able to return them in a action, like:


    no, sorry, actions don't have a 'return' value at the moment,
    and it's also not possible to call any action inside an action parameter,

    Quote

    I'm now using a foreach loop, but krpano said it doesn't have a foreach action command.

    right, krpano doesn't have such


    best regards,
    Klaus

  • Hi Klaus,

    I'm using the foreach action now. My pano's are called Pano[001], Pano[002] and so on... Now i'm trying to pass a counting variable (i) to the index of the Pano[index] array. But then it isn't Pano[001] but Pano[1]. Is there anyway to make sure the variable has 3 digits?

    Declan

    p.s. Do you think it is possible for the next release to be able to use arrays with the Scene node, and have a new function (like AddHotspot, AddLensflare) for scenes: AddScene?

    Edited 3 times, last by rctdeclan (April 12, 2010 at 6:55 PM).

  • Hi Klaus,
    My pano's are called Pano[001], Pano[002] and so on... Now i'm trying to pass a counting variable (i) to the index of the Pano[index] array. But then it isn't Pano[001] but Pano[1]. Is there anyway to make sure the variable has 3 digits?

    Hey Declan,

    Can you post your xml code for this? If you've implemented this in the following way:

    Code
    <pano name="001" caption="This is pano 001, it is really fun"/>
    <pano name="002" caption="This is pano 002, it is really cool"/>
    <pano name="003" caption="This is pano 003, it is really wee"/>

    then you've actually created 4 pano nodes.

    pano[0].name is null pano[0].caption is null
    pano[1].name is n1 pano[1].caption is "This is pano 001, it is really fun"
    pano[2].name is n2 pano[2].caption is "This is pano 002, it is really cool"
    pano[3].name is n3 pano[3].caption is "This is pano 003, it is really wee"

    Note that because a number was used as the name, then it was treated as an index and the name for each node was automatically assigned to n1 (or n2 or n3).
    Thus, whether you are addressing with two leading zeros or not, you are always using a numercal index, you are not indexing by name (in other words, 001 is the same as 1).

    You should be able to address these as Pano[001] or Pano[1], each will access the pano with the caption "This is pano 001, it is really fun"

    Here's some code that addresses the arrays in 3 different ways, directly (ie. Pano[001]), through an argument (ie Pano[%1]), and finally using a variable (ie Pano[%tmp]).. Note that in each case we use the two leading zeros but this would have worked equally well without them.

    I hope I'm understanding your problem correctly. The leading 00's shouldn't make a difference if I understand you correctly because you're indexing by number, not by name.

    steve

    Edited once, last by pinsane (April 13, 2010 at 9:19 AM).

  • Hi Steve,

    Here's my problem (Adressing with actions like LoadScene() )

    Code
    <scene name="pano[001]" >
    </scene>

    Currently, i'm still making my scenes statically. By using the Arrays in krpano, i'm hoping to be able to create Scenes dynamically (by actions).

    I'm not sure how to call my scenes.

    I can call them pano[001] , pano_001 or 001 (I think the last one is the best)


    An example
    My TourData node

    Code
    <TourData fovmin="60" fovmax="100">              <!--The TourData node with all global settings for all scenes.-->
    		<pano name="The first panorama" 		caption="the first caption"                   tilesize="745"             firstlevel="5215"       secondlevel="2608"           thirdlevel="1304"               startH="20"           startV="10"             startFov="30"            endH="0"                    endV="30"                   endFov="90">
    			<hotspot	target=002	ath=-93	atv=-3 	/>
    		</pano>
    		<pano name="The second panorama" 		caption="the second caption "             tilesize="745"             firstlevel="5215"       secondlevel="2608"           thirdlevel="1304                startH="20"           startV="10"             startFov="30"            endH="0"                    endV="30"                   endFov="90">
    			<hotspot	target=001	ath=-93	atv=-3 	/>
    		</pano>
    </TourData>

    As i've said before, I want to dynamically create scenes and hotspots.

    So it would theoretically be something like this

    Code
    foreach(TourData.pano.count,i,
    NewScene(i);
    foreach(TourData.pano.hotspot.count,j,
    NewHotspot(j,i);
    );
    );

    and offcourse for the hotspots: (I don't really know how to make sure the hotspot is only for the current scene)

    for some extra information about other actions:

    Code
    <action name="ViewScene">
    		loadscene(Pano[%1], null, MERGE, BLEND(1))
    	</action>
            </action name="IntoAnimation">
            		sub(tempnum,%1,1);
    		tween(view.hlookat,get(TourData.pano[%tempnum].endH),2);
    		tween(view.vlookat,get(TourData.pano[%tempnum].endV),2);
    		tween(view.fov,get(TourData.pano[%tempnum].endFov),2);
            </action>


    If really like if the AddScene function would be added to krpano, Klaus told me in another thread, this isn't possible yet.
    He said that for now, it is only possible to set it with set(scene.content,PUTALLTHEXMLHERE);
    But i hope that he can make scene adding and deleting dynamically, like addhotspot and addlensflare.


    So my 2 questions are:

    • Can i use an array with the scene node, so i don't have to give them a name?
    • Could a addscene function be added to krpano?
  • Hi,

    i'd like to know how this "%" thing works exactly. I think if I understood that a lot of things would fall in place.

    with %1,%2,%3,... and so on you will get the content of a parameter which will be set when calling an action,

    with array[%varname] you can use a variable as index when accessing a item of an array element,
    but this % usage will be let undocumented, in the next release it will be possible to use get() inside
    an array index, e.g. array[get(varname)],

    best regards,
    Klaus

  • Hi,

    This is the 4th edit.

    Few questions:

    1. Why do we need to give a node a name before we can use it as an array?
    2. the following:

    I have an action:

    Code
    <action name="MakeMyHotspots">
    NewLink(000,000);
    NewLink(000,001);
    NewLink(000,002);
    NewLink(000,003);
    </action>

    But i can't change it to this:

    Code
    <action name="MakeMyHotspots">
    foreach(Tour.pano.link,i,NewLink(000,get(i)));
    </action>

    I will get an error:

    ERROR: remove - unknown array item - n2

    (I'm using foreach action from this tread: http://www.krpano.com/forum/wbb/inde…reach#post12865)

    Edited 4 times, last by rctdeclan (April 24, 2010 at 1:41 PM).

Participate now!

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