objects as parameter?

  • Atm I cleaning some code I have. It loops through an array, reads the properties and then build some plugins. A part of this is sending the object(?) name to an action so that action can read the properties. for instance:

    Code
    for(set(i,0), i LT panorama.pano.count, inc(i), createtext(get(i)));
    Code
    <action name="createtext">
        addplugin(text_%1);
        copy(plugin[text_%1].html, panorama.pano[%1].title);
    </action>

    you can imagine alot of panorama.pano[%1].someattribute happens, and later even a second depth is added panorama.pano[%1].variant[%2].title

    I was wondering if there was a trick in wich I could just throw the object itself (instead of the name/index) in the action.

    Code
    createtext(panorama.pano[get(i)]);

    I then could do for instance

    Code
    copy(plugin[someplugin].html, %1.title);

    perhaps alsoo not so clean, but im trying to reduce the code. Perhaps better would be creating an object name;

    Code
    set(object, %1);
    copy(plugin[someplugin].html, object.title);

    or

    Code
    copy(object, panorama.pano[get(i)].variant[get(j)]);
    copy(plugin[someplugin].html, object.title);


    Just throwing some ideas...

  • Hi,

    note - the action parameters will be passed just via 'copy and paste' to the %N placeholders in the actions,
    so when using there - get(i) - can be problematic when the 'i' variable will be changed during processing,

    but the other thoughts should already work out of the box,

    e.g. when doing:

    Code
    copy(obj, plugin[pname]);
    set(obj.visible, true);

    'obj' will be a reference to the plugin element,
    and accessing all attributes of it via the new reference is directly possible,

    best regards,
    Klaus

  • Hi What do you mean with:

    Zitat

    note - the action parameters will be passed just via 'copy and paste' to the %N placeholders in the actions,
    so when using there - get(i) - can be problematic when the 'i' variable will be changed during processing,

    i could be 0 to any positive number but its assigned to the first parameter, being %1. So even if i is 0, it wouldnt affect %0 since Im not reassining %0, only %1. I can't even imaigine how I would set the %0 from within the action call creatext();

    About the other thing, my versioning was wrong, the latest version already supports this :)

    Although I have issues with loadstyle now. Normally I could create a style, put some default properties on it, and then in an action still overwrite it if conditions met. But with the loadstyle of the latest version, it seems to always apply the ones in loadstyle() and doesnt get overwritten by setters later on.

  • Hi,

    i could be 0 to any positive number but its assigned to the first parameter, being %1. So even if i is 0, it wouldnt affect %0 since Im not reassining %0, only %1. I can't even imaigine how I would set the %0 from within the action call creatext();

    %0 can't be set, this is always the name of the called action,


    Although I have issues with loadstyle now. Normally I could create a style, put some default properties on it, and then in an action still overwrite it if conditions met. But with the loadstyle of the latest version, it seems to always apply the ones in loadstyle() and doesnt get overwritten by setters later on.

    do you mean when calling loadstyle() or when using style="..."?
    the style="..." tags were now resolved directly after loading the xml to make it also possible to use preload and keep in styles, but the loadstyle() function itself should still work as before...?

    best regards,
    Klaus

  • Well, I updated krpano to the latest version, and first thing I noticed was that some stuff didnt work anymore. I checked al the code, and the problem lies in the fact that the style applied using loadstyle couldnt be overwritten.

    ex (typed it from head, so could have some typos)

    in version of 5 - 10, the onclick set in add_image() is set if isflash == true.

    In the latest version this code keeps the style loaded with loadstyle persistent (doesnt allow for overwriting).

    concerning the other point:

    Zitat

    %0 can't be set, this is always the name of the called action,

    This is what I said, but you said:

    Zitat

    note - the action parameters will be passed just via 'copy and paste' to the %N placeholders in the actions,
    so when using there - get(i) - can be problematic when the 'i' variable will be changed during processing,

    I dont understand how get(i) can be problematic. Its just a number put in %1.

  • Hi,

    is that exactly the code that you were using?
    it contains some problems, so that I would wonder if that code had ever worked...?

    e.g. here the brackets in the actions names would cause that they were never callable:
    <action name="load_images()">
    <action name="add_image()">

    then this part here:
    txtadd(tplugin, 't_image_', get(i));
    addplugin(tplugin);
    add_image(tplugin, get(i));

    would cause create always a plugin named 'tplugin',
    and also pass the name 'tplugin' to the add_image action,

    to use the content of the tplugin variable using get(tplugin) would be necessary,
    e.g.
    txtadd(tplugin, 't_image_', get(i));
    addplugin(get(tplugin));
    add_image(get(tplugin), get(i));

    best regards,
    Klaus

  • nah like I said, i did it by head, since my real code is a bit more complex...

    My real code is:

    In this example I use an if else for the onclick. But in the version of 05-10 this wasnt nessesary. I could put the "else" in the style and overwrite it if the if statement came true. I had several actions with this construct that worked with version 05-10.

  • I cant recreate the problem either. In my current tour its still broken. I removed all the xml related to generating a bunch of textfields in a for loop. Only left the bare minimum. It doesnt work. If I then copy it to a new blank tour, the exact same code works. Both krpano versions are the same. I'm puzzled, but I'd guess this is is something I have to figure out on my own.

    any idea what could prevent a style not to be overwritten? or is it because perhaps so much is going on in the main pano, that the loadstyle is applied to late? (so i add a custom onclick, and then the loadstyle gets triggered, even if the loadstyle is before the onclick?).

  • Hi,

    any idea what could prevent a style not to be overwritten?

    there is no direct relation between a style and the plugin/hotspot element,

    when calling - loadstyle(style) - then just all attributes from <style> element will be copied/set to the <plugin>/<hotspot> element,
    that means after calling the loadstyle() - any attribute in the plugin/hotspot can be set (overwritten) again,

    best regards,
    Klaus

Jetzt mitmachen!

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