Calling ads from ads.lua

Hi guys,

Can you help me with below code  :slight_smile:

I want to keep clean my main.lua as much as possible…

So I want to call ads from ads.lua, and not from main.lua.

ads.lua :

local ads = require( "ads" ) --------------------------------------------------------------  Initializing the Providers if ( system.getInfo("platformName") == "Android" ) then    ads.init( "admob", "your-ad-unit-id-here", adMobListener ) else    ads.init( "iads", "com.yourcompany.yourapp", iAdsListener ) end ads.init( "vungle", "yourAppID", vungleListener ) --------------------------------------------------------------  Initializing the Providers -------------------------------------------------------------- Coding the callback listners local function vungleListener( event ) -- Video ad not yet downloaded and available if( event.type == "adStart" and event.isError ) then if( system.getInfo("platformName") == "Android" ) then ads:setCurrentProvider( "admob" ) else ads:setCurrentProvider( "iAds" ) end ads.show( "interstitial" ) elseif( event.type == "adEnd" ) then -- Ad was successfully shown and ended; hide the overlay so the app can resume. ads.hide() else print( "Received event", event.type ) end return true end local function iAdsListener( event ) if( event.isError ) then local options = {     effect = "fade",     time = 500,     isModal = true } composer.showOverlay( "selfpromo", options ) end return true end local function adMobListener( event ) if ( event.isError ) then local options = {     effect = "fade",     time = 500,     isModal = true } composer.showOverlay( "selfpromo", options ) end return true end --------------------------------------------------------- Starting the Ad Chain local params = { isAnimated = false, isAutoRotation = true, } ads:setCurrentProvider( "vungle" ) ads.show( "interstitial", params )

How to use/call above code from main.lua?

Many thanks!  :smiley:

Ivan 

How are you calling your ads module in your other scenes/modules? I would hypothesize that if you are calling:

local adsModule = require("ads")

or similar, then you are essentially overwriting your the ads module you just created. 

You are right Alex@Panc! 

Sometimes I am so into things, I cannot see wood`s from the tree  :smiley:

I will call all of above code from level.lua, and I will not create ads.lua, because it makes no sense…

Thank you Alex.

How are you calling your ads module in your other scenes/modules? I would hypothesize that if you are calling:

local adsModule = require("ads")

or similar, then you are essentially overwriting your the ads module you just created. 

You are right Alex@Panc! 

Sometimes I am so into things, I cannot see wood`s from the tree  :smiley:

I will call all of above code from level.lua, and I will not create ads.lua, because it makes no sense…

Thank you Alex.