Video reward Appodeal

Hello everyone

My problem is this, I’m trying to insert publicity into my app with appodeal.

To get started I downloaded the sample code and changed the app key. Everything works but I can not figure out where to put the code for the video reward. I searched around and tells me to put that into the “playbackEnded” phase of the method used in appodeal.init().

To handle this I did something like that:

local txt\_info = display.newText( "nil text", 20, 200, "gameFont", 25 ) txt\_info.anchorX = 0 local txt\_info2 = display.newText( "nil text", 20, 250, "gameFont", 25 ) txt\_info2.anchorX = 0 local txt\_info3 = display.newText( "nil text", 20, 300, "gameFont", 25 ) txt\_info3.anchorX = 0 -- Ad listener function local function appodealListener( event ) txt\_info.text = "Event:"..event.phase..event.type..event.data -- Exit function if user hasn't set up testing parameters if ( setupComplete == false ) then return end -- Successful initialization of the Appodeal plugin if ( event.phase == "init" ) then print( "Appodeal event: initialization successful" ) -- An ad loaded successfully elseif ( event.phase == "loaded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad loaded successfully" ) -- The ad was displayed/played elseif ( event.phase == "displayed" or event.phase == "playbackBegan" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad displayed" ) -- The ad was closed/hidden/completed elseif ( event.phase == "hidden" or event.phase == "closed" or event.phase == "playbackEnded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad closed/hidden/completed" ) -- The user clicked/tapped an ad elseif ( event.phase == "clicked" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad clicked/tapped" ) -- The ad failed to load elseif ( event.phase == "failed" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad failed to load" ) elseif( event.phase == "playbackBegan") then txt\_info2.text = "Start Video"..tostring( os.time( ) ) elseif( event.phase == "playbackEnded") then txt\_info3.text = "Finish Video"..tostring( os.time( ) ) end end

Although everything works, the texts do not change at all, so I think they are not getting into the method. Probaiblemte I’m wrong. can you help me?

Hi @jake1987.jj,

Does even the first text object (“txt_info”) change/update at any point? Are you getting any Lua errors in the console?

Brent

I do not get any error. The text never changes is what I do not understand, at least once it should enter the method

This is the code I am using:

-- Require libraries/plugins local appodeal = require( "plugin.appodeal" ) -- Preset Appodeal app keys (replace these with your own) -- These must be gathered within the Appodeal developer portal: https://www.appodeal.com/apps local appKey if ( system.getInfo("platformName") == "Android" ) then -- Android appKey = "my\_key" elseif ( system.getInfo("platformName") == "iPhone OS" ) then --iOS appKey = "[IOS-APP-KEY]" end local txt\_info = display.newText( "qui", 20, 200, "gameFont", 25 ) txt\_info.anchorX = 0 local txt\_info2 = display.newText( "qui", 20, 250, "gameFont", 25 ) txt\_info2.anchorX = 0 local txt\_info3 = display.newText( "qui", 20, 300, "gameFont", 25 ) txt\_info3.anchorX = 0 -- Ad listener function local function appodealListener( event ) txt\_info.text = "Event:"..event.phase..event.type..event.data -- Exit function if user hasn't set up testing parameters if ( setupComplete == false ) then return end -- Successful initialization of the Appodeal plugin if ( event.phase == "init" ) then print( "Appodeal event: initialization successful" ) -- An ad loaded successfully elseif ( event.phase == "loaded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad loaded successfully" ) -- The ad was displayed/played elseif ( event.phase == "displayed" or event.phase == "playbackBegan" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad displayed" ) -- The ad was closed/hidden/completed elseif ( event.phase == "hidden" or event.phase == "closed" or event.phase == "playbackEnded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad closed/hidden/completed" ) -- The user clicked/tapped an ad elseif ( event.phase == "clicked" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad clicked/tapped" ) -- The ad failed to load elseif ( event.phase == "failed" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad failed to load" ) elseif( event.phase == "playbackBegan") then txt\_info2.text = "Start Video"..tostring( os.time( ) ) elseif( event.phase == "playbackEnded") then txt\_info3.text = "Finisch Video"..tostring( os.time( ) ) end end local function testButton(event) local id = event.target.id appodeal.show( "rewardedVideo" ) end local btn = display.newRect( 300, 100, 50, 50 ) btn:setFillColor( 1, 0, 0 ) btn.id = "standard" btn:addEventListener( "tap", testButton ) -- Init the Appodeal plugin appodeal.init(appodealListener, { appKey = appKey, supportedAdTypes = {"rewardedVideo", "banner", "video" }, testMode = false })

I think your problem is in the long if else statement. Add the type to the if statements and you should be fine. Something like this would probably work:

local function appodealListener( event ) txt\_info.text = "Event:"..event.phase..event.type..event.data -- Exit function if user hasn't set up testing parameters if ( setupComplete == false ) then return end -- Successful initialization of the Appodeal plugin if ( event.phase == "init" ) then print( "Appodeal event: initialization successful" ) -- An ad loaded successfully elseif ( event.phase == "loaded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad loaded successfully" ) -- The ad was displayed/played elseif ( event.phase == "displayed" or event.phase == "playbackBegan") then print( "Appodeal event: " .. tostring(event.type) .. " ad displayed" ) if event.type=="rewardedVideo" then txt\_info2.text = "Start Video"..tostring( os.time( ) end -- The ad was closed/hidden/completed elseif ( event.phase == "hidden" or event.phase == "closed" or event.phase == "playbackEnded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad closed/hidden/completed" ) if event.type=="rewardedVideo" then txt\_info3.text = "Finisch Video"..tostring( os.time( ) ) end -- The user clicked/tapped an ad elseif ( event.phase == "clicked" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad clicked/tapped" ) -- The ad failed to load elseif ( event.phase == "failed" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad failed to load" ) end end

I have much simpler needs so this is what my callback looks like:

M.appodealListerner = function(event) if ( event.phase == "init" ) then M.bannerAdsReady = true elseif event.phase == "playbackEnded" and event.type=="rewardedVideo" then M.print("Send reward event.") M.eventDispatcher:dispatchEvent( { name="rewarded", data = true } ) end end

You are right I made a small mistake,

however txt_info is changed while txt_info2 and txt_info3 no.

It does not seem to come into control.

I do not know what to do

Delete this line:

-- Exit function if user hasn't set up testing parameters if ( setupComplete == false ) then return end 

And add this to the top of the listener

local json = require("json") local eventJson = json.encode(event) if eventJson ~= nil then print(json.prettify(eventJson)) end

perfect thank you very much

Hi @jake1987.jj,

Does even the first text object (“txt_info”) change/update at any point? Are you getting any Lua errors in the console?

Brent

I do not get any error. The text never changes is what I do not understand, at least once it should enter the method

This is the code I am using:

-- Require libraries/plugins local appodeal = require( "plugin.appodeal" ) -- Preset Appodeal app keys (replace these with your own) -- These must be gathered within the Appodeal developer portal: https://www.appodeal.com/apps local appKey if ( system.getInfo("platformName") == "Android" ) then -- Android appKey = "my\_key" elseif ( system.getInfo("platformName") == "iPhone OS" ) then --iOS appKey = "[IOS-APP-KEY]" end local txt\_info = display.newText( "qui", 20, 200, "gameFont", 25 ) txt\_info.anchorX = 0 local txt\_info2 = display.newText( "qui", 20, 250, "gameFont", 25 ) txt\_info2.anchorX = 0 local txt\_info3 = display.newText( "qui", 20, 300, "gameFont", 25 ) txt\_info3.anchorX = 0 -- Ad listener function local function appodealListener( event ) txt\_info.text = "Event:"..event.phase..event.type..event.data -- Exit function if user hasn't set up testing parameters if ( setupComplete == false ) then return end -- Successful initialization of the Appodeal plugin if ( event.phase == "init" ) then print( "Appodeal event: initialization successful" ) -- An ad loaded successfully elseif ( event.phase == "loaded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad loaded successfully" ) -- The ad was displayed/played elseif ( event.phase == "displayed" or event.phase == "playbackBegan" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad displayed" ) -- The ad was closed/hidden/completed elseif ( event.phase == "hidden" or event.phase == "closed" or event.phase == "playbackEnded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad closed/hidden/completed" ) -- The user clicked/tapped an ad elseif ( event.phase == "clicked" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad clicked/tapped" ) -- The ad failed to load elseif ( event.phase == "failed" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad failed to load" ) elseif( event.phase == "playbackBegan") then txt\_info2.text = "Start Video"..tostring( os.time( ) ) elseif( event.phase == "playbackEnded") then txt\_info3.text = "Finisch Video"..tostring( os.time( ) ) end end local function testButton(event) local id = event.target.id appodeal.show( "rewardedVideo" ) end local btn = display.newRect( 300, 100, 50, 50 ) btn:setFillColor( 1, 0, 0 ) btn.id = "standard" btn:addEventListener( "tap", testButton ) -- Init the Appodeal plugin appodeal.init(appodealListener, { appKey = appKey, supportedAdTypes = {"rewardedVideo", "banner", "video" }, testMode = false })

I think your problem is in the long if else statement. Add the type to the if statements and you should be fine. Something like this would probably work:

local function appodealListener( event ) txt\_info.text = "Event:"..event.phase..event.type..event.data -- Exit function if user hasn't set up testing parameters if ( setupComplete == false ) then return end -- Successful initialization of the Appodeal plugin if ( event.phase == "init" ) then print( "Appodeal event: initialization successful" ) -- An ad loaded successfully elseif ( event.phase == "loaded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad loaded successfully" ) -- The ad was displayed/played elseif ( event.phase == "displayed" or event.phase == "playbackBegan") then print( "Appodeal event: " .. tostring(event.type) .. " ad displayed" ) if event.type=="rewardedVideo" then txt\_info2.text = "Start Video"..tostring( os.time( ) end -- The ad was closed/hidden/completed elseif ( event.phase == "hidden" or event.phase == "closed" or event.phase == "playbackEnded" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad closed/hidden/completed" ) if event.type=="rewardedVideo" then txt\_info3.text = "Finisch Video"..tostring( os.time( ) ) end -- The user clicked/tapped an ad elseif ( event.phase == "clicked" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad clicked/tapped" ) -- The ad failed to load elseif ( event.phase == "failed" ) then print( "Appodeal event: " .. tostring(event.type) .. " ad failed to load" ) end end

I have much simpler needs so this is what my callback looks like:

M.appodealListerner = function(event) if ( event.phase == "init" ) then M.bannerAdsReady = true elseif event.phase == "playbackEnded" and event.type=="rewardedVideo" then M.print("Send reward event.") M.eventDispatcher:dispatchEvent( { name="rewarded", data = true } ) end end

You are right I made a small mistake,

however txt_info is changed while txt_info2 and txt_info3 no.

It does not seem to come into control.

I do not know what to do

Delete this line:

-- Exit function if user hasn't set up testing parameters if ( setupComplete == false ) then return end 

And add this to the top of the listener

local json = require("json") local eventJson = json.encode(event) if eventJson ~= nil then print(json.prettify(eventJson)) end

perfect thank you very much