Ok, first off, I know this is relating to Appodeal, but I feel as though it is more of a external modules and function calling question than an appodeal specific question, thus I placed it here. If you feel it should be moved please do so.
So, after alot of research and some trial and error, I have found that it is stated to be best that the appodeal be initially required in the main, as well as the init(). Because the appodeal.init(adListener, {appKey = “…”}) mentions the adListener function and because of scoping I need to add the adListener function within the main.lua as well.
My current main.lua is as follows:
--------------------------------------------------------------------------------- -- -- main.lua -- --------------------------------------------------------------------------------- -- require the composer library local composer = require "composer" -- require the appodeal library, ad the listender, and init local appodeal = require( "plugin.appodeal" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.isError ) elseif ( event.phase == "loaded" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "displayed" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "clicked" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "closed" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "hidden" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "failed" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "playbackBegan" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "playbackEnded" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "dataReceived" ) then print(tostring(event.phase)..": "..tostring(event.type)) elseif ( event.phase == "playbackEnded") and (event.type == "rewardedVideo") then print("Video Reward Playback Ended") rewardThem() end end appodeal.init( adListener, { appKey= "111111111111111111111111111111" } ) appodeal.load( "banner" ) appodeal.load( "rewardedVideo" ) -- hide the status bar display.setStatusBar( display.HiddenStatusBar ) -- Reserve channel 1 for background music audio.reserveChannels( 1 ) -- Seed the random number generator math.randomseed( os.time() ) -- load logo scene before going to menu composer.gotoScene( "logo", {effect = "fade", time = 3000} )
Now I am trying to figure out how to get the adListener to… “listen” once I continue on to other scenes, such as my gameOnePlayer.lua. Also, once it listens, and “hears” that a reward video ad is complete I want it to run the rewardThem() function which will actually be in my gameOnePlayer.lua.
I read through the globals tutorial as well as the external modules tutorial and still need a little guidance. So, multi questions coming up.
First, if I create the adListener(event) function in the main.lua, does it continue through the life of the app or do I need to somehow reference it in each scene?
Second, how do I get the rewardThem() function which is actually located in the gameOnePlayer.lua to work? My first thought was that I needed to require("gameOnePlayer) as well in the main, and create a local variable for gameOnePlayer.rewardThem() function. Problem is, I am confusing my self when attempting to do this. Should I use the below code within the gameOnePlayer.lua or just call it a local function like normal?
function scene:rewardThem() --Give reward code here end
Third, and hopefully lastly, if I load something in the main.lua like a sound or in this case
appodeal.load("rewardedVideo")
does it stay loaded even when progressing through other scenes and can I call it with the same function as normal or do I have to reference the main.lua some how?