returning a value from a javascript action

  • Hi all

    so far all examples i got was to call functions and then change something in krpano plugins or positions (there is one example in the skin file
    but i did not find any to "return a value"


    Code
    <action name="register_javascript_actions2" type="Javascript" autorun="preinit">
      krpano.actions.getlanguagecontent = function( labelId , type , outresult)
        {
    		args[2]='ola';
    		outresult = 'ola';
    }
    </action>

    when i call

    Code
    getlanguagecontent(get(hotspot[%1].hsname) , 'auditorio' , outputfromfunction);

    i was hoping to get 'ola' in the outputfromfunction variable bit it stays null all the time
    tried with args and setting the variable directly and i always get null
    i see the function running because i added some "console.log" and it displays

    thank you for the help

  • the args array is used in type=Javascript actions.
    your register_javascript_actions2() is type=Javascript,
    but krpano.actions.getlanguagecontent() is working as a normal js function:

    important:
    if you create functions like that, you must check/verify the variable type of the input variables.
    ie. if you would create an add function and do a+b you have to ensure that a and b are numbers first!

    and... its not a must, but in krpano xml actions the return value target is normally the first argument.
    i.e. https://krpano.com/docu/actions/#mul

    *smile*

  • hi,

    thank you for your reply.

    That wont do (i think) in my case because of atomic execution. All the function will execute synchronous but i think that the get variable in krpano variable, after, the execution of the jsfunction, can get a different value if some executions occur at the same time.

    I turned into a jsget with 2 "envelope" actions since i can pass %1, %2, etc to jsget but i could not manage to pass a variable, neither by name, neither with get but %3 was fine

    i had a problem while ago with detecting if the variable was defines and i was hoping to solve it today with a js action.

    i was hoping to get this code inside my xml but i couldn't... may be later i'll understand the connections with parameters bewteen actions and javascript actions and plain javascript
    from time to time i try and i always end by solving it but not in the way which i think is the correct

    thanks again

Participate now!

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