Handling duplicate functions across plugins

  • While write some plugins, I have encountered a few times that there are conflicts in terms of functions/actions/styles.

    For example:

    Plugin 1: (simpleplugin.xml)
    <action name="dosomething" scope="local"> doA() </action>

    Plugin 1: (anotherplugin.xml)
    <action name="dosomething" scope="local"> doB() </action>

    in tour.xml, we have
    <include url='simpleplugin.xml' />
    <include url='anotherplugin.xml' />
    <action name="dosomething" scope="local"> doC() </action>

    What happens is that the functionality of "dosomething" is determined by the one that is "seen" last by krpano. Even if it is called from plugin 1, the functionality executed will be the one that is last "seen/loaded" by krpano.

    I have not tested it with javascript plugins yet. But I assume that (global) actions defined withing the javascript plugin will have the same behaviour.

    Same with layers/styles/...

    For example,

    Plugin 1:
    <layer name="overlay"></layer>

    Plugin 2:
    <layer name="overlay"></layer>

    Is not going to end up well *rolleyes*

    I have read https://krpano.com/docu/xml/#action.scope, but that scope only applies to variables defined within the action.

    My question
    - is there a way to define private scopes for functions (and layers/hotspots/...) so that when I call an action from plugin1, the action from plugin1 is executed (and not the action from plugin2)
    - any other suggestions? I now work around this with a naming convention (plugin1_dosomething()), but that adds a lot of typing *squint*

    Looking forward to your suggestions!
    KME

  • Tested with javascript plugins:

    plugin1:
    krpano.actions.dosomething = function() { ... };

    plugin2:
    krpano.actions.dosomething = function() { ... };

    And in tour.xml I have

    <plugin name="simpleplugin" url="simpleplugin.js"/>
    <plugin name="simpleplugin2" url="simpleplugin2.js"/>
    <action name="dosomething"> ... </action>

    when i call "dosomething", the action from plugin2 is used.

  • all the xml you load is merged,
    so when you define the same action (name) in multiple xmls,
    only the last one will exist.

    actions are stored in the action array, you can check them by

    Code
    for(set(i,0), i LT action.count, inc(i), 
    trace(action[get(i)].name);
    );


    there can't be 2 actions with the same name.
    this works exactly the same as with layers and hotspots
    (check the docs about krpano arrays)

    also mind that an included xml is not a krpano plugin.
    real plugins are only possible in js and offer more possibilities
    there you could create "local" actions like plugin[myname].dosomething()

Participate now!

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