fuse.checkLoaded()

Type Function
Return value Boolean
Revision Release 2024.3703
Keywords ads, advertising, monetization, fuse, checkLoaded
See also fuse.init()
fuse.load()
fuse.show()
fuse.*

Overview

Returns true or false depending on whether an ad of the specified zone has been loaded and cached.

Note that Fuse is already set up to pre-cache a few ads when you call fuse.init(), so usually there's no need to call fuse.checkLoaded() prior to calling fuse.show(). Generally, the only time to call fuse.checkLoaded() is when you're calling fuse.show() and you want to ensure that Fuse has pre-cached an ad from a specific zone.

Syntax

fuse.checkLoaded( [params] )
params (optional)

Table. A table which specifies properties for the fuse.checkLoaded() query. Within this table, you should specify the zone key with a string value representing the ad zone to query.

Example

local fuse = require( "plugin.fuse" )

-- Preset an ad zone
local adZone = "Menu"

-- Event listener function
local function adListener( event )

    if ( event.isError ) then
        print( "Fuse error: " .. event.response )
    else
        if ( event.phase == "init" ) then
            -- Fuse system initialized; load/cache a zone-specific ad
            fuse.load( { zone=adZone } )

        elseif ( event.phase == "loaded" ) then
            if ( event.isError == false ) then
                -- Ad successfully loaded for requested zone
            end
            
        elseif ( event.phase == "shown" ) then
            -- An ad finished showing
        end
    end
end

-- Initialize the Fuse service
fuse.init( adListener )

-- Sometime later, check if the ad has been loaded/cached
local isLoaded = fuse.checkLoaded( { zone=adZone } )
-- If true, show the ad
if ( isLoaded == true ) then
    fuse.show( { zone=adZone } )
end