Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Accessing parent scene function from overlay outside the original composer scene.
Started by gudrutis1 Mar 17 2020 09:19 AM

3 replies to this topic

Best Answer XeduR @Spyric , 17 March 2020 - 12:47 PM

You can pass a reference to a function by simply stating:

local composer = require( "composer" )

local function printSomething()
    print( "something!" )
end

composer.myFunction = printSomething

-- Then you can call this anywhere you want as long as you've required composer in the file.
composer.myFunction()

i.e. all you need is to add a reference to the function to some variable or table that is within scope of wherever you are trying to call the function from.

 

In the example at the docs, event.parent is scene, so having added a method to it like event:resumeGame() means that the function would be accessible anywhere where scene is accessible.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

gudrutis1

[GLOBAL: userInfoPane.html]
gudrutis1
  • Enthusiast

  • 37 posts
  • Corona SDK

Code I post for example works but what I really want is to make a functions sequence to work after button pressed. I made a note in the code. How I can achieve that?

 
 

--Scene
--function outside scene

function scene:rearrange()
       --do something
end


--Overlay
--function outside scene

function scene:resume(a)
       a.rearrange()
end


function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then

       --NOTE. Widget button e.g (onRelease = scene:resume(event.parent))  

       scene:resume(event.parent)

end



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,246 posts
  • Corona SDK

That's explained quite well here: https://docs.coronalabs.com/api/library/composer/showOverlay.html



[TOPIC: post.html]
#3

gudrutis1

[GLOBAL: userInfoPane.html]
gudrutis1
  • Enthusiast

  • 37 posts
  • Corona SDK

What explained very well is how to get data from composer scene (create and show) using event.parent. What I am looking for is actually how to pass event.parent to a function outside composer scene through a widget button. Or maybe there is an option to pass parameters to a function without running it?



[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,246 posts
  • Corona SDK

  Best Answer

You can pass a reference to a function by simply stating:

local composer = require( "composer" )

local function printSomething()
    print( "something!" )
end

composer.myFunction = printSomething

-- Then you can call this anywhere you want as long as you've required composer in the file.
composer.myFunction()

i.e. all you need is to add a reference to the function to some variable or table that is within scope of wherever you are trying to call the function from.

 

In the example at the docs, event.parent is scene, so having added a method to it like event:resumeGame() means that the function would be accessible anywhere where scene is accessible.


  • pixec likes this


[topic_controls]
[/topic_controls]