Hi So I have successfully implemented the ads part for my app. The ads show perfectly fine. The problem is that I have 2 scenes and for the time being, I’ve coded each scene to require the ads API and it loads them from scratch each time a scene is loaded since I always remove the previous scene everytime I load a new scene. Now I want to implement the ads part from just 1 external module. Based on the ads and external module tutorials I’ve read, it should be possible to just initialize the ads once and just call it to show whenever I want and not have to reinitialize again and again like my current code is doing now. This is my code so far and it works fine.
local ads = require “ads”
local function adMobListener( event )
if ( event.isError ) then
storyboard.showOverlay( “selfpromo” )
end
return true
end
ads.init( “admob”, “XXXXXXXXXXXXXXXXXXXXXXXXX”, adMobListener )
local params = {
x=0,
y=0,
isAnimated = false,
isAutoRotation = true,
}
ads:setCurrentProvider(“admob”)
ads.show( “banner”, params )
My idea is that I’d want each scene to just say…
local adsmodule = require “adsmodule”
adsmodule.show
Then it automatically shows the ads because the initialization has already been done.
I have made an external module called ‘adsmodule.lua’ and these are the codes under.
local M = {}
local M.ads = require “ads”
– functions are now local:
local function adMobListener( event )
if ( event.isError ) then
storyboard.showOverlay( “selfpromo” )
end
return true
end
local function initialize()
M.ads.init( “admob”, “XXXXXXXXXXXXXXXXXXXXXXXXXXXXX”, adMobListener )
end
local function show()
local params = {
x=0,
y=0,
isAnimated = false,
isAutoRotation = true,
}
ads:setCurrentProvider(“admob”)
ads.show( “banner”, params )
end
M.adMobListener = adMobListener
M.initialize = initialize
M.show = show
return M
I apologize if I did any ridiculous coding because I just got into external modules, based on the tutorials I’ve read, my mind told me to code like this and it doesn’t work. I’d appreciate it if anybody could guide me on this. Thank you very much.