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

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

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


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

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


    (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):


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

    good luck!

    steve

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!