in "oncomplete" cannot access parent variable - caller.

  • !! UPDATE !!
    I'm using krpano ver. 1.20.11.
    ------------------

    I don't know exactly when it started 'oncomplete' running differently.
    I think it could be from krpano ver. 1.20 updates which had had replaced its sound interface from HTML5-Audio to webAudio API.
    --- if possible, I'd like to know when it started exactly just for information.


    - this action works as usual : playsound(_name_, _source_, false, 1, oncomplete() );


    But in a local scope action, the 'oncomplte' cannot access caller.
    'caller' is not the caller itself who acually called the action, but trace() shows null.

    Code
    <action autorun='onstart'>	callwith(hotspot[anhotspot], anaction);</action>
    <hotspot name='anhotspot' />
    <action name='anaction' scope='local'>	trace(caller.name); // anhotspot	playsound(_name_, _source_, false, 1, trace(caller.name) ); // undefined or null</action>


    in that case, if you needed get the extra information from the caller - the hotspot named 'anhotspot' is NOT possible in 'oncomplete'.

    Yes, in different way, it could be solved problem,
    However, I'd like to know if there's another way to get the action caller in easy way OR it's impossible to be accessed.

    Thanks.

    Edited once, last by Kabkee (July 12, 2023 at 8:34 AM).

  • playsound(_name_, _source_, false, 1, trace(get(caller.name)) );


    Unfortunately, that's not the point.
    did you tried that in scope='local' action as i mentioned above?
    it's not the matter of using get() though.

    if it's the matter of using get(), I didn't post it at all.

  • trace(caller.name); shows "anhotspot" as expected when you call the action with callwith()
    its kind of logical that the playsound callback cant have anaction or anhotspot...
    1) its not called from anaction() but from playsound()
    2) such a callback is not a local scope action
    but you can pass any information when you create/pass the callback

    maybe that works:
    calc(local.callback, "trace("+caller.name+")");
    playsound(_name_, _source_, false, 1, get(callback));


  • Thank you for your prompt response.
    and you right mentioned that's why I'm finding a way to get access some variables out of the local scope of playsound's 'oncomplete'.

    I know there's no anaction, no anhotspot in the scope of 'oncomplete', it makes me feel like it's so much isolated from other scopes.
    But, it can access to "global" !!

    The following code works:

    Code
    <action name='anaction' scope='local'>
    trace(caller.name);
    copy(global.callerName, caller.name);
    playsound(narration, get(sound_source[effect_popup].url), false, 1, trace(get(global.callerName)) );
    </action>


    However, it's not the way what I do NOT want.
    So, here's my solution. make a xml element and using its' attribues like below:

    Code
    <some_setting tempcaller='' />
    <action name='anaction' scope='local'>
    trace(caller.name);
    copy(some_setting.tempcaller, caller.name);
    playsound(narration, get(sound_source[effect_popup].url), false, 1, trace(some_setting.tempcaller) );
    </action>


    As you expected, the above codes are work properly.


    Unfortunately, your codes below are not working.

    Code
    maybe that works:
    calc(local.callback, "trace("+caller.name+")");
    playsound(_name_, _source_, false, 1, get(callback));


    Maybe.. or somehow, there could be a better solution to get access to caller from oncomplete???
    *whistling* *rolleyes* *confused*


  • strange.. it works fine here
    proof of concept -->

  • strange.. it works fine here
    proof of concept -->


    Thank you for your example. it works. Yes, I know.
    But ah...

    I got to know that I mistitled this post and I should had to mention the words "oncomplete of playsound - SoundInterface"


    I re-point that
    "I want a way to get caller of local scoped action which called from a hotspot in oncomplete of ""playsound"" action."

    There's no way so far, and i wrote this post.
    AND I'm finding other's opinions, its possibilities, or the exact reason why it is.


    ""I hope that you tried my code which mentioned the beginning.
    specially, have your attention on "playsound" action and in the oncomplete session, you cannot get any caller in there.""

  • it doesnt matter playsound or other, you can not trace back the caller history
    the callback (oncomplete) is called from playsound() and you can't get a higher caller
    the trick to hardcode the caller (or any information) into the callback is a workaround
    it works the exactly same for playsound as for the example

  • OK.
    As you called the 'oncomplete' as a "callback", YES I think it's real javascript callback function which could not access other territories, variables.
    Specially, in such a limited environment like krpano javascript type action. (Somehow, it works so in krpano to get intergrated with pure Javascript library - hower js)


    As Hyung mentioned in the thread - https://krpano.com/forum/wbb/inde…&threadID=19413
    The two different callback - "donecall" and "oncomplte" - look like the same, but work differently.


    Then, could I make the conclusion of this tread?

    Why I made this tread is to get access caller (in local scoped action) in oncomplete(callback function of playsound, Sound Interface).
    However, it's not possible to get the history of callback because of the mechanism or so.


    Related to this thread,
    one thing left question driven from Hyung is that.


    1. HOW donecall of tween and oncomplete of playsound (sound interface) are differently working in Krpano?

    2. WHAT makes donecall of tween and oncomplete of playsound (sound interface) work different in the same situation?


    I'd like to get your opinion or advice to use them correctly with right knowledge.
    Thank you in advance.


  • @ Kabkee
    sorry this is not a simple topic...
    but keep in mind that there are actions without or with (local) scope and then there is callwith() which is not the same!
    local scope actions use the caller object, actions called with callwith() work differently
    eg. callwith(hotspot[abc], trace(name)); will trace the hotspots name
    instead of searching the variable in the globals, it is searched in the hotspot/layer first.
    event functions for layers and hotspots (like onclick) use that 2nd approach
    callwith(hotspot[abc], myaction()); or with <hotspot ... onclick="myaction()" .../>
    will set the caller object, if myaction is a local scope action.
    otherwise myaction() can use the hotspots attributes directly, like globals.
    as said its not a simple topic and in the end you must test things out
    anyway, in any case only the direct caller is accessible! you cant get a higher caller

  • @ Kabkee
    sorry this is not a simple topic...
    but keep in mind that there are actions without or with (local) scope and then there is callwith() which is not the same!
    local scope actions use the caller object, actions called with callwith() work differently
    eg. callwith(hotspot[abc], trace(name)); will trace the hotspots name
    instead of searching the variable in the globals, it is searched in the hotspot/layer first.
    event functions for layers and hotspots (like onclick) use that 2nd approach
    callwith(hotspot[abc], myaction()); or with <hotspot ... onclick="myaction()" .../>
    will set the caller object, if myaction is a local scope action.
    otherwise myaction() can use the hotspots attributes directly, like globals.
    as said its not a simple topic and in the end you must test things out
    anyway, in any case only the direct caller is accessible! you cant get a higher caller
    thats why the example above hardcodes the callers name inside the callback function
    this way you have the needed information


  • @ Kabkee
    anyway, in any case only the direct caller is accessible! you cant get a higher caller
    thats why the example above hardcodes the callers name inside the callback function
    this way you have the needed information

    Yes. that makes me sense. All about the local scope and callwith you said, I agree with them.
    To make simple the topic of this thread, I brought a new sample code below.

    Today I have a deep thinking time on this, and I got an idea *w00t* *attention* why it is.
    My guess is that It is because "klaus make this so".
    I don't know it's in purpose or not, but please review the blow code.


    Playsound oncomplete, tween donecall works the same.
    All returns "got YOU".

    Code
    <action name='anaction'>
    	set(getMyName, 'got YOU');
    	tween(view.hlookat, 90,,,
    		trace(getMyName); // got YOU
    	);
    	playsound(narration, get(sound_source[effect_popup].url), false, 1,
    		trace(getMyName); // got YOU
    	);
    </action>


    Playsound oncomplete, tween donecall works differently.


    My Guess,
    1. tween is genuine krpano action and its donecall works remaining in krpano.
    2. playsound is a plugin action which is integrated with howlerJs.
    3. In the code of integration, (maybe) in the listening event callback function don't get any information because the callback function is running in an isolated function which is in static mode.


    What do you think?

    I think. Only Klus can reveal the fact how this possible.
    I'm just curious and this has not been solved clearly for few days :(

Participate now!

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