To use this library in your Defold project, add the needed version URL to your game.project
dependencies from Release add to path github credentials.
For example:
https://username:your_token@github.com/OCRV-RRW/PlatformSDK/archive/refs/tags/v0.3.zip
Open game.project and make sure to reference /platform-sdk/template/engine_template.html in the .html Shell field in the HTML5 section.
Sdk Initialization.
platform_sdk = require("platform-sdk.platform-sdk")
function init(self)
platform_sdk.init()
platform_sdk.LoadingComplete()
endYou can subscribe to the complete initialization.
platform_sdk = require("platform-sdk.platform-sdk")
function init(self)
platform_sdk.subscribeToComplete(
function ()
platform_sdk.getUser(function (user)
if(user == nil) then
print("Couldn't load user")
end
print(user["name"] .. " " .. user["id"])
end)
end
)
platform_sdk.init()
platform_sdk.loadingComplete()
endplatform_sdk.init - start platform-sdk initialization.
platform_sdk.loadingComplete - send an html message to the parent about the completion of the game loading.
platform_sdk.getUser - get user.
platform_sdk.subscribeToComplete - subscribe to the end of initialization.
platform_sdk.addScoreToSkill (callback, skillName, score) - add score to user skill
function sendMessageToIframe(message: object){
const frame = document.getElementById("game_iframe") as HTMLIFrameElement | null
if (frame && frame.contentWindow){
frame.contentWindow.postMessage(message, "https://example.ru")
}
}sendMessageToIframe({type: "start-game"})window.addEventListener("event_name", _ => {
// ... your code
})window.addEventListener("is-loaded", _ =>{
console.log("game is loaded")
})is-loaded - invoked on game is loaded.
start-game - send to initialize the sdk for the platform.