Results 1 to 5 of 5

Thread: How To Access Local Variables/ Functions From Scene Overlay?

  1. #1

    How To Access Local Variables/ Functions From Scene Overlay?

    This might sound like an obvious question, but how do you call variables and functions that are local to an overlay from the current scene? I know you can pass variables from the current scene to the overlay, but how do you pass variables from the overlay to the current scene? It works if the variables are global, but I know global variables are bad so how then do you pass local variables?
    I tried making the function from

  2. #2

    How To Access Local Variables/ Functions From Scene Overlay?

    but I don't see this explained anywhere so is this the right way of doing things? And will the overlay's scene:destroy still clear the function? I tested this and for some reason I was still able to call the sceneOverlay.myFunction() even though I did composer.hideOverlay() with recycling not true. Can someone please explain.

  3. #3

    How To Access Local Variables/ Functions From Scene Overlay?

    void the issue. Store or exchange the values via a commonly required module.

    Sorry I don't have a better answer, but I must admit I've never tried reaching into a overlay. I rarely reach into scenes that way and rarely use overlays, so you can see how that combines to never doing this.

    Having said that, the overlay is nothing more than a scene so you should be able to reach in and get any function or variable you have assigned to the scene object. So, don't make the variables 'local'. Make them fields on the scene objects.

  4. #4

    How To Access Local Variables/ Functions From Scene Overlay?

    only then does the function become nil. Why does that happen? Shouldn't the function have been destroyed along with the other scene objects without me having to explicitly state?

  5. #5
    Actually this is a really cool thing that Composer does with Overlays.

    Back in the Storyboard days, when you closed an overlay, it would trigger the parent's hideScene function as well as the overlay scene's hideScene function (or whatever they were named). Composer only calls scene:hide() for the overlay. The parent scene doesn't get any notification that the overlay is closing. So we added a feature.

    In both scene:show() and scene:hide() and possibly scene:create(), the event table includes a member called parent which just so happens to be the actual "scene" object from the parent.

    This means you can do things in the parent like:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •