Play an ad||doc136059

September 20, 2022

Format

AdHelper:videoAd(place, adIndex, callBack)
  • The class to which the function belongs:AdHelper

Description

Play ads based on scene name and ad position index


Precautions

  • Ad slot index can only have up to 9

Parameters

Variable name type Description
place string scene name
adIndex number Ad slot index
callBack function Callback


Value Returned

type Description
function Cancel the function executed by the result callback function


Parameters of the callback function

Variable name type Description
videoAdResult AdHelper.VideoAdResult Play ad results
place string scene name
index number Ad slot index


Code Samples

Make sure to define and report the advertising scene before you can play the advertisement

local AdHelper = Game.GetService("AdHelper")
AdHelper:defineAdPlace('place1')
AdHelper:reportAdPlace('place1')

Play the advertisement with the scene as place1 and the advertisement position index as 1

local cancelfunc = AdHelper:videoAd('place1',1,function(videoAdResult,place,index)
    if videoAdResult == AdHelper.VideoAdResult.FINISHED then      --Watch success
        print('Watch out')
    elseif videoAdResult == AdHelper.VideoAdResult.FAILED then    --Watch failed
        print('Watch the failure')
    elseif videoAdResult == AdHelper.VideoAdResult.CLOSE then     --Exit without reading
        print('Exit while watching')
    end
end)