defold (official)
defold/extension-kaiads/kaiads
Functions and constants for interacting with the KaiAds SDK.
- GitHub: defold/extension-kaiads — pinned to
2.0.0(released while Defold 1.7.0 was current)- Pick a release from defold/extension-kaiads releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as kaiads from "kaiads"
- Pick a release from defold/extension-kaiads releases and add its Source code (zip) URL (or a packaged
Functions
kaiads.init(publisher_id: string)
Initialise KaiAds.
kaiads.init("2b30c65e-efde-4930-990e-ded207899766")Parameters
publisher_id:string— Id of the publisher
kaiads.set_listener(listener: function)
Listen to events from the KaiAds SDK.
local function = on_kaiads_event(self, event, code)
if event == kaiads.PRELOAD_OK then
print("KaiAds has successfully preloaded an ad")
elseif event == kaiads.AD_DISPLAY then
print("KaiAds is showing an ad")
elseif event == kaiads.AD_CLOSE then
print("The user closed the ad!")
elseif event == kaiads.AD_CLICK then
print("The user clicked on the ad!")
else
print("Something went wrong", code)
end
end
kaiads.set_listener(on_kaiads_event)Parameters
listener:function— function to call when a KaiAds event is received from the SDK.
kaiads.preload(config: string)
Preload an ad.
local banner_config = {
app = "mygame",
slot = "menu",
test = 0,
timeout = 5 * 1000,
h = 264,
w = 240,
container = "ad-container"
}
kaiads.preload(json.encode(banner_config))
local fullscreen_config = {
app = "mygame",
slot = "gameover",
}
kaiads.preload(json.encode(fullscreen_config))Parameters
config:string— Ad configuration as a JSON encoded string.
kaiads.show()
Show an ad. You must have called preload() and received a callback that the ad was preloaded before attempting to show an ad.
kaiads.set_listener(function(self, event, code)
if event == kaiads.PRELOAD_OK then
kaiads.show()
end
end)
kaiads.preload(config)Constants
kaiads.PRELOAD_ERROR
Event sent when an error occurred while trying to preload an ad
kaiads.PRELOAD_OK
Event sent when an ad was successfully preloaded
kaiads.SHOW_ERROR
Event sent when an error occurred while trying to show an ad
kaiads.AD_DISPLAY
Event sent when an ad is displayed
kaiads.AD_CLICK
Event sent when an ad is clicked
kaiads.AD_CLOSE
Event sent when an ad is closed