Appodeal and rewards (again).

Hi,

I have a workflow question.  I am creating a platform game, some of the levels only allow the user to attempt them once unless they watch the reward video.  I am playing the video no problem, however I am not sure how to work things.

I assume that I should only call the “appodeal.init” once? If this is the case then I should place this, along with the listener, in my main.lua.

Now if this is the case then how do I know if the add is finished in my main code? I know I can check if event.phase==“playbackEnded” and event.type==“rewardedVideo” in the event listener, but how do I act on this on a completely different scene?  What I want to happen is that once the video is watched that the button changes from “watch video” to “repeat”.

I can think of two options, have an “appodeal.init” in each scene where I need to check for the state of something happening, or add a runtime enterframe event that checks the value of some variable that is updated in the main listener.

Is either of these the right way?

Thanks for your help.

Craig

I found that for my specific purposes custom events worked quite well.  In the main listener in main.lua I have the following;

[lua]

local function adListener( event )

  if ( event.phase == “init” ) then  – Successful initialization

   

 elseif event.phase==“playbackEnded” and event.type==“rewardedVideo” then

    Runtime:dispatchEvent({name = “rewardedVideoEnded”})

  end

[/lua]

and then in the scene where I am using the rewarded video I have the following;

[lua]

disposeGroup.rewardedVideoEnded = function(target, event)

    – do something since video has finished

end

Runtime:addEventListener(“rewardedVideoEnded”, disposeGroup)

appodeal.show( “rewardedVideo” )

[/lua]

Not sure if this is the best way, but it works.  Hope this might help someone.

Craig

Your .init() call and listener function should be in main.lua or a Lua module only loaded in main.lua once.

As for how to respond, there are may ways to notify your scene of the event.

The easiest might be to use a quasi-global table as documented here: https://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

In your listener you can set a value in the table to indicate that the video was watched and in the scene where you allow them to access the next level you can test against that variable. Composer’s getVariable() and setVariable() can also be used for this.

The other cool thing you can do is attach a function to your scene object:

– scene to do work:

function scene.doSomethingAwesome()       -- do something when the rewarded video is complete end

then in your listener function

local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization elseif event.phase=="playbackEnded" and event.type=="rewardedVideo" then local currSceneName = composer.getSceneName( "current" ) local scene = composer.getScene( currSceneName ) if scene.doSomethingAwesome then scene.doSomethingAwesome() end end end

error, replace :

local currSceneName = composer.getSceneName( “current” )
local scene = composer.getScene( currCeneName )

with :

local currSceneName = composer.getSceneName( “current” )
local scene = composer.getScene( currSceneName )

I found that for my specific purposes custom events worked quite well.  In the main listener in main.lua I have the following;

[lua]

local function adListener( event )

  if ( event.phase == “init” ) then  – Successful initialization

   

 elseif event.phase==“playbackEnded” and event.type==“rewardedVideo” then

    Runtime:dispatchEvent({name = “rewardedVideoEnded”})

  end

[/lua]

and then in the scene where I am using the rewarded video I have the following;

[lua]

disposeGroup.rewardedVideoEnded = function(target, event)

    – do something since video has finished

end

Runtime:addEventListener(“rewardedVideoEnded”, disposeGroup)

appodeal.show( “rewardedVideo” )

[/lua]

Not sure if this is the best way, but it works.  Hope this might help someone.

Craig

Your .init() call and listener function should be in main.lua or a Lua module only loaded in main.lua once.

As for how to respond, there are may ways to notify your scene of the event.

The easiest might be to use a quasi-global table as documented here: https://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

In your listener you can set a value in the table to indicate that the video was watched and in the scene where you allow them to access the next level you can test against that variable. Composer’s getVariable() and setVariable() can also be used for this.

The other cool thing you can do is attach a function to your scene object:

– scene to do work:

function scene.doSomethingAwesome()       -- do something when the rewarded video is complete end

then in your listener function

local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization elseif event.phase=="playbackEnded" and event.type=="rewardedVideo" then local currSceneName = composer.getSceneName( "current" ) local scene = composer.getScene( currSceneName ) if scene.doSomethingAwesome then scene.doSomethingAwesome() end end end

error, replace :

local currSceneName = composer.getSceneName( “current” )
local scene = composer.getScene( currCeneName )

with :

local currSceneName = composer.getSceneName( “current” )
local scene = composer.getScene( currSceneName )