Skip to content

potatojam/defold-vkbridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VK Bridge for Defold

This is an open-source project. It is not affiliated with Vkontakte LLC.

Installation

You can use it in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field add a link to the ZIP file of a specific release.

Supported Platforms

Platform Status
Browser (HTML5) Supported âś…

Getting Started

Initialization

To get started, you need to initialize the SDK using the init method.

local vkbridge = require("vkbridge.vkbridge")

local function init_handler(self, err)
    if err then
        print("Something bad happened :(", err)
    else
        --
        -- SDK is ready!
        -- From this moment, you can use all available functions, i.e. invoke ads, get player data, etc.
        --
    end
end

function init(self)
    vkbridge.init(init_handler)
end

The game.project Settings

[vk_bridge]
auto_init = true
wv_banners = true
interstitial_day_limit = 50
interstitial_hour_limit = 10
interstitial_delay = 90
  • auto_init boolean optional The application initializes the VKBridge on startup. To prevent VKBridge from being initialized, set false. Then the initialization will be when vkbridge.init(init_handler) is called. Default true.
  • wv_banners boolean optional Loads a script containing a WebView banner. Default false.
  • interstitial_day_limit number optional Set a limited number per day for interstitial ads. Default: no limit. If set to 0, then there is no limit.
  • interstitial_hour_limit number optional Set a limited number per hour for interstitial ads. Default: no limit. If set to 0, then there is no limit.
  • interstitial_delay number optional Set a limit per seconds for interstitial ads. Default: no limit. If set to 0, then there is no limit.

Lua API

VKBridge JavaScript SDK uses ES6 Promise for asynchronous operations. For Lua API promises were replaced with callback functions with arguments (self, err, result), where

  • self userdata - Script self reference.
  • err table - Error code if something went wrong. If successful: err = nil.
  • result table - Data if the operation should return something.

vkbridge.init(callback)

Initialize the Vk Bridge

Parameters

  • callback function required callback with response data

vkbridge.send(name, [, data[, callback]])

Sends a message to native client and returns the object with response data

Parameters

  • name string required The VK Bridge method
  • data table|nil optional Message data object
  • callback function optional callback with response data

vkbridge.subscribe(fn)

Subscribes a function to events listening. The function will handle each vkbridge.send and some additional events. In order not to miss events, you can subscribe before calling vkbridge.init.

Parameters

  • fn function required Function to be subscribed to events. function(self, data)

vkbridge.unsubscribe(fn)

Unsubscribes a function from events listening

Parameters

  • fn function required Event subscribed function

vkbridge.supports(method)

Checks if an event is available on the current device

Parameters

  • method string required The VK Bridge method

vkbridge.is_webview()

Returns true if VK Bridge is running in mobile app, or false if not

vkbridge.is_iframe()

Returns true if VK Bridge is running in iframe, or false if not

vkbridge.is_embedded()

Returns true if VK Bridge is running in embedded app, or false if not

vkbridge.is_standalone()

Returns true if VK Bridge is running in standalone app, or false if not

Additional Lua API

All of these functions can be called with vkbridge.send. They are written for convenience.

vkbridge.check_interstitial(callback)

Check if there is the interstitial ad available

Parameters

  • callback function required callback with response data

vkbridge.show_interstitial(callback)

Show interstitial ads

Parameters

  • callback function required callback with response data

vkbridge.check_rewarded(use_waterfall, callback)

Check if there is the rewarded ad available to serve

Parameters

  • use_waterfall boolean required Whether to use the mechanism for displaying interstitial advertising in the absence of rewarded video.
  • callback function required callback with response data

vkbridge.show_rewarded(use_waterfall, callback)

Show rewarded ads

Parameters

  • use_waterfall boolean required Whether to use the mechanism for displaying interstitial advertising in the absence of rewarded video.
  • callback function required callback with response data

vkbridge.storage_set(key, value, callback)

Set the value of the variable whose name is passed in the key parameter. Key life is 1 year.

Parameters

  • key string required Key name, [a-zA-Z_-0-9]. The maximum length is 100 characters.
  • value string required The value of the variable. Only the first 4096 bytes are stored.
  • callback function required callback with response data

vkbridge.storage_get(key, callback)

Return the values of the variables.

Parameters

  • key string|table required Names of keys or key [a-zA-Z_-0-9]. Can be a table or a string
  • callback function required callback with response data

vkbridge.storage_get_keys(key, callback)

Return the names of all variables.

Parameters

  • count number required The number of variable names to get information about.
  • offset number|nil required The offset required to select a particular subset of variable names.
  • callback function required callback with response data

vkbridge.clear_limits()

Clear interstitial limits if used

vkbridge.get_user_info(callback)

Allows you to get basic data about the profile of the user who launched the application

Parameters

  • callback function required callback with response data

WebView Banner

WebView Banner is a banner which is displayed either above or below the application. It is available only for mobile devices running in the VKontakte application.

WebView Banner

Be sure to enable wv_banners = true in the game.project.

vkbridge.load_wv_banner(callback)

Load WebView banner. Available for mobile only.

Parameters

  • callback function required callback with response data

vkbridge.unload_wv_banner()

Unload WebView banner. Available for mobile only. Return true on success.

vkbridge.show_wv_banner()

Show WebView banner. Available for mobile only. Return true on success.

vkbridge.hide_wv_banner()

Hide WebView banner. Returns true on success.

vkbridge.refresh_wv_banner(callback)

Refresh WebView banner. Available for mobile only.

Parameters

  • callback function required callback with response data

vkbridge.set_wv_banner_configs(position, count)

Set WebView banner configs.

Parameters

  • position string required Banner location. Can be top or bottom.
  • count number Number of banners in a column. Default 1

Limits

Vk advises to make limiting the display of ads. The platform itself does not block display of ads. However, ads can be turned off for you if they think that you are cheating on it. Limits only work for vkbridge.show_interstitial(callback) function. Limits use storage to save data for day and hour. Keys: interstitial_day_limit and interstitial_hour_limit. To the received data will be added some key(exceeded, delay_exceeded, hour_limit_exceeded, day_limit_exceeded), If the limit is exceeded. The table looks like this:

{
  delay_exceeded = true, -- if delay limit is exceeded
  hour_limit_exceeded = true, -- if hour limit is exceeded
  day_limit_exceeded = true, -- if day limit is exceeded
  result = true, -- the result will always be true
  exceeded = true -- if any limit is exceeded
}

Credits

Made by PotatoJam.

This project uses the source code of YaGames.

For example used:

Dirty Larry

Druid

License

MIT license.