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.

1

Monday, April 19th 2010, 2:52am

How can I add to strings in xml?

I have been searching the forums for an answer, but no luck, so here's my question:
(Thank you in advance to anyone who reads this)

I am trying to make a tour with 3 languages, so I have made several information window popups in the three languages.

I want to get the url value of a plugin as a string and then subtract some letters off the string, and then add some letters.

I mean I want to get a url value like "image_e.png" (my english image) then take off the "e.png" part and add a "c.png" (my chinese image path)

If this would work, it would be easy to change values like
image1e.png to image1c.png
image2e.png to image2c.png
image3e.png to image3c.png

This is what I want to do.

I was not able to figure out how to do this, so I decided to use the name of the plugin instead and just add to it. I'm still not sure how to make this work.

So for example I have

Source code

1
 <plugin name="info1" url="images/info1e.png" keep="true"  visible="false" alpha="0" origin="center" width="342" height="290"  selectable="false" onclick="set(plugin[i_hide1].visible,false);  set(plugin[i_show1].visible,true); tween(plugin[info1].alpha,0);  set(plugin[info1].enabled,false);" />


I want to use name="info1" and an action called show_chinese to calculate the correct url and then assign it.

Source code

1
2
3
4
5
<action name="show_chinese">
set(path,get(plugin[info1].name)); // should set the variable $path = info1
path = path + "c.png"                 	// not correct syntax, but I want this line to add a c.png to $path
set(plugin[info1].url, path);       	// This line will set a new value for [info1].url
</action>


So in summary, I want to learn how to do this the easiest way for now (probably the second approach), but also want to learn all about how to manipulate strings in my xml. Any advice or links to other threads/documentation would be very appreciated.

Thank you!

P.S. Are nested if loops possible in xml?

2

Monday, April 19th 2010, 7:11am

RE: How can I add to strings in xml?


I want to get the url value of a plugin as a string and then subtract some letters off the string, and then add some letters.


I'm not aware of a way to subtract letters off of a string (other than passing the string into javascript, manipulating it, and then passing it back), but you can concatenate (add) strings using the txtadd command:

Source code

1
2
3
set(pathroot,"images/info1");
set(language,"c");
txtadd(plugin[info].url,get(pathroot),get(language),".png");

Here we set the info plugin's url to "images/info1c.png" based on the value of the variable 'language'. If you changed the language variable to e then the code would change the url to "images/info1e.png"

Another way to concatenate strings is by using arguments passed into actions, but the txtadd command is the most general solution.

P.S. Are nested if loops possible in xml?

You can nest if statements. For instance:

Source code

1
2
3
4
5
6
7
8
9
10
11
if (lang == "chinese",
    set(language,"c");
<!--else-->,
    if (lang == "english",
        set(language,"e");
    <!--else-->,
        if (lang == "french",
            set(language,"f");
        );
    );
);

(the <!--else-->, includes a comment for clarity, but only the comma is required)

looping is accomplished through recursion, and nested recursive loops are possible. It is also possible to add actions that provide a traditional looping syntax (which is nestable):

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
<!--	_while_action
	private function to execute while loop body action -->
<action name="_while_action">
	trace("Error in while loop: push/pop stack corrupted"); <!-- this line should never execute -->
</action>
<!--	while <condition.str> <body.str>
	while loop function which repeatedly iterates the action as long as the condition is true-->
<action name="while"> <!--condition.str,body.str-->
	push(action[_while_action].content);
	set(action[_while_action].content,"if(%1,%2;_while_action(););");
	_while_action();
	pop(action[_while_action].content);
</action>

By adding the above snippet of code you can now write loops (including nested loops):

Source code

1
2
3
4
5
6
7
8
9
10
11
<action name="while_test3">
	set(a,-360);
	while(a LE 360,
		set(b,-360);
		while(b LE 360,
			trace("looping a=",get(a)," b=",get(b));
			inc(b,90);
		);
		inc(a,90);
	);
</action>


good luck!

steve

3

Tuesday, April 20th 2010, 11:21am

Steve,

Thank you so much for your clear reply. It's exactly what I needed to know. And I guess I don't need to subtract to make this work as long as I can add.

Thanks again! *smile*