Hi guys,
I’m trying to activate a function after an ad displayed. The goal of this function -> get a new character, either by using in game credits or by watching an ad. The same function is used for both, but only working properly when I use it with in game credits. This is how I’ve set up the ad listener:
function functions.applovinAdListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.isError ) -- Load an AppLovin ad applovin.load() elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded print( event.type ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) elseif ( event.phase == "displayed" or event.phase == "playbackBegan" ) then -- The ad was displayed/played print( event.type ) elseif ( event.phase == "hidden" or event.phase == "playbackEnded" ) then -- The ad was closed/hidden print( event.type ) functions.freeRandomBall() applovin.load() elseif ( event.phase == "clicked" ) then -- The ad was clicked/tapped print( event.type ) end end applovin.init(functions.applovinAdListener, { sdkKey="MyKey" })
The “MyKey” string is filled in correctly in my code.
This is the code for the function:
function functions.freeRandomBall(event) getRandomBallValue = mRand(2,6) if getRandomBallValue == 2 then transitions.boughtBall = transition.to(boughtBall[2], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) transitions.boughtBallTxt = transition.to(boughtBallTxt[2], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) settings.ball2 = true loadsave.saveTable(settings, "circleGameSettings.json") availableBar[2].alpha = 1 print("ball2 = ", settings.ball2) elseif getRandomBallValue == 3 then transitions.boughtBall = transition.to(boughtBall[3], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) transitions.boughtBallTxt = transition.to(boughtBallTxt[3], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) settings.ball3 = true loadsave.saveTable(settings, "circleGameSettings.json") availableBar[3].alpha = 1 print("ball3 = ", settings.ball3) elseif getRandomBallValue == 4 then transitions.boughtBall = transition.to(boughtBall[4], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) transitions.boughtBallTxt = transition.to(boughtBallTxt[4], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) settings.ball4 = true loadsave.saveTable(settings, "circleGameSettings.json") availableBar[4].alpha = 1 print("ball4 = ", settings.ball4) elseif getRandomBallValue == 5 then transitions.boughtBall = transition.to(boughtBall[5], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) transitions.boughtBallTxt = transition.to(boughtBallTxt[5], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) settings.ball5 = true loadsave.saveTable(settings, "circleGameSettings.json") availableBar[5].alpha = 1 print("ball5 = ", settings.ball5) elseif getRandomBallValue == 6 then transitions.boughtBall = transition.to(boughtBall[6], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) transitions.boughtBallTxt = transition.to(boughtBallTxt[6], {time = 3500, alpha = 1, onComplete = functions.removeBoughtBallandTxt}) settings.ball6 = true loadsave.saveTable(settings, "circleGameSettings.json") availableBar[6].alpha = 1 print("ball5 = ", settings.ball5) end end function functions.watchAdForCoins(event) applovin.show() end
I feel like it should work just fine, but it’s not for some reason, the misbehaviour is hard to explain because sometimes it executes the function twice, sometimes it doesn’t executes the function… I don’t see a patern in the misbehaviour. Could someone help?
Kind regards
Bram


