एक छोटा-सा स्क्रिप्ट, जिसे किसी भी HTML5 गेम में डाला जाए, जो आपके लिए Khelo Zone से बात करता है — खाते, सर्वर-सत्यापित स्कोर, लीडरबोर्ड, उपलब्धियां, कॉइन, क्लाउड सेव, और भी बहुत कुछ। यह पेज पूरा रेफ़रेंस है, चाहे आप प्लेटफ़ॉर्म के लिए गेम बना रहे हों या सिर्फ़ जानना चाहते हों कि यह सब कैसे जुड़ता है।
अपने गेम के खुद के कोड से पहले स्क्रिप्ट टैग जोड़ें, session.init() कॉल करें, और जब भी कोई राउंड खत्म हो तो स्कोर सबमिट करें। बस इतना ही न्यूनतम इंटीग्रेशन है।
<!-- Add this before your game's own code, in every game build -->
<script src="../_sdk/platform-sdk.js"></script>
<script>
// gameId is read automatically from the page URL — nothing to hardcode.
Platform.session.init().then(({ user, capabilities }) => {
console.log('Playing as', user ? user.display_name : 'guest');
});
// ...your game runs, then when a round ends:
const runId = Platform.scores.newRunId(); // hold this for the whole run
Platform.scores.submit(1250, { durationSeconds: 42, runId }).then((result) => {
if (result.accepted) console.log('New best?', result.best);
});
</script>स्क्रिप्ट पाथ रिलेटिव है (../_sdk/platform-sdk.js), एब्सोल्यूट नहीं — हर गेम /<your-game>/index.html पर रहता है, SDK एक लेवल ऊपर, और यह सही तरीके से रिज़ॉल्व होता है चाहे आप लोकल टेस्ट कर रहे हों या आपका गेम असल में डिप्लॉय हो चुका हो।
आपका गेम एक सैंडबॉक्स्ड iframe के अंदर चलता है और कभी भी प्लेटफ़ॉर्म के API या डेटाबेस से सीधे बात नहीं करता — यह कभी API की या किसी खिलाड़ी का सेशन टोकन नहीं देखता। SDK होस्ट पेज को छोटे मैसेज (postMessage) भेजता है, जो असली API को कॉल करने वाली एकमात्र चीज़ है, वास्तविक लॉग-इन खिलाड़ी के सेशन का उपयोग करके। आपका गेम केवल सादे async फ़ंक्शन कॉल करता है और सादे ऑब्जेक्ट वापस पाता है।
अपने गेम की HTML फ़ाइल को बिना किसी होस्टिंग के सीधे खोलें, और SDK नोटिस करता है कि इसके आसपास कोई प्लेटफ़ॉर्म नहीं है और चुपचाप एक लोकल-ओनली मोड पर फ़ॉलबैक करता है। हर कॉल फिर भी अटकने या एरर देने की बजाय समझदारी से रिज़ॉल्व होती है, ताकि आप कोई गेम कहीं भी एम्बेड होने से पहले पूरी तरह बना और टेस्ट कर सकें।
// Nothing to write — this is automatic. Open your game's index.html
// directly (double-click the file, or any local dev server) and the SDK
// detects there's no platform host around it, then:
Platform.isStandalone; // true
// - Platform.session.init() resolves immediately with a local guest user
// - Platform.scores.submit() saves to THIS browser's localStorage only
// - achievements/missions/economy calls resolve honestly as unavailable
// The exact same file then works for real the moment it's embedded.हर फ़ीचर के हर डिप्लॉयमेंट पर लाइव होने की गारंटी नहीं है। Platform.capabilities आपको बताता है कि अभी वास्तव में क्या जुड़ा हुआ है, ताकि आप अंदाज़ा लगाने की बजाय एक बार जांच सकें — हालांकि व्यवहार में आप आमतौर पर सीधे नेमस्पेस को कॉल कर सकते हैं और उस पर भरोसा कर सकते हैं कि यह ईमानदारी से जवाब देगा।
प्लेटफ़ॉर्म के साथ हैंडशेक करें और बुनियादी सेशन जानकारी पढ़ें।
const { user, capabilities } = await Platform.session.init();
// user is null if the player isn't logged in, or if you're testing this
// file directly outside the platform (see "Standalone mode" below).
Platform.session.getConfig(); // { gameId, protocolVersion, standalone }मौजूदा खिलाड़ी की प्रोफ़ाइल।
const user = await Platform.player.get();
// { id, display_name, avatar_url, level, xp, coins }खत्म हुआ राउंड सबमिट करें। वैधता और पुरस्कार सर्वर तय करता है — कभी यह मान न लें कि आपने जो स्कोर भेजा वही रिकॉर्ड होने वाला स्कोर है।
const runId = Platform.scores.newRunId();
const result = await Platform.scores.submit(score, { durationSeconds, runId });
// { accepted, scoreId?, reward?: { coins, xp }, reason? }
// Safe to retry with the SAME runId after a flaky network call —
// the server treats a repeated runId as the same submission, never
// double-credits coins/XP.अपने गेम की मौजूदा रैंकिंग पढ़ें।
const rows = await Platform.leaderboard.get('daily'); // 'weekly'/'allTime' reserved
// [{ rank, user_id, display_name, avatar_url, score }, ...]एक-बार के अनलॉक, सर्वर-साइड पर लागू किए गए ताकि आपको खुद कभी "पहले से दिया गया" ट्रैक न करना पड़े।
// Call this the moment you decide it's earned — as many times as you want.
// The server guarantees it's granted to a given player at most once.
Platform.achievements.unlock('no_hit_run');प्लेटफ़ॉर्म के दैनिक मिशन सेट की प्रगति रिपोर्ट करें।
Platform.missions.updateProgress('play_3_games', 1);खिलाड़ी के कॉइन को इन-गेम पर्क पर खर्च करें। एटॉमिक — कभी नेगेटिव नहीं जा सकता।
// Raw coin spend for an in-game perk (extra life, skip level, etc).
const result = await Platform.economy.spend(50, 'extra_life');
if (result.ok) grantExtraLife();क्लाउड-सिंक्ड की/वैल्यू सेव डेटा, ऑफ़लाइन-फ़र्स्ट।
// Offline-first: writes go to localStorage instantly (your game never
// waits on a network round trip), and sync to the server in the background
// for a logged-in player. get() reads the local cache first, then refreshes
// it if the server has a newer value.
await Platform.storage.set('settings', { difficulty: 'hard' });
const settings = await Platform.storage.get('settings', { difficulty: 'normal' });छोटे पॉलिश हेल्पर्स जिन्हें होस्ट की बिल्कुल ज़रूरत नहीं होती।
document.getElementById('fullscreenBtn').onclick = () => {
Platform.ui.isFullscreen() ? Platform.ui.exitFullscreen() : Platform.ui.requestFullscreen();
};
Platform.ui.vibrate(40); // short haptic buzz, no-ops silently if unsupportedएक प्लेटफ़ॉर्म-व्यापी साउंड/म्यूज़िक म्यूट प्राथमिकता — हर गेम में साझा एक सेटिंग, जिसे पॉज़ मेन्यू से टॉगल किया जाता है जो प्लेटफ़ॉर्म पहले से देता है। आपका गेम इसे केवल पढ़ता है।
// One guard at the top of whatever plays a sound — that's the entire integration.
function beep(freq, dur) {
if (Platform.audio.sfxMuted) return;
// ...actually play the sound
}
// Or react live to changes (fires immediately with the current state, then on every change):
Platform.audio.onChange(({ sfxMuted, bgmMuted }) => {
backgroundMusic.muted = bgmMuted;
});मॉनेटाइज़ेशन हुक — आज ही इंटीग्रेट करना सुरक्षित है, विज्ञापन नेटवर्क जुड़ने से पहले।
// Only ever call this from a natural break point — game over, or an
// explicit "watch ad" button. Never mid-play.
const { shown } = await Platform.ads.showRewarded('extra_life');
if (shown) grantExtraLife();
// Today this always resolves { shown: false, reason: 'not_implemented' } —
// no ad network is wired in yet. Integrate the call now and it starts
// actually showing ads the day one is chosen, with no code changes on your end.फ़ायर-एंड-फ़ॉर्गेट इवेंट ट्रैकिंग। छूटा हुआ इवेंट आपके गेम में कभी एरर के रूप में सामने नहीं आता।
Platform.analytics.track('level_complete', { level: 4, timeSeconds: 96 });इंटीग्रेट करना शुरू करने के लिए जो कुछ भी चाहिए, बिना किसी बिल्ड टूलिंग के।
सादा-JS बिल्ड — इसे सीधे एक ही स्क्रिप्ट टैग के साथ किसी गेम में डाल दें।
डाउनलोड करेंटाइप्ड TypeScript सोर्स, बंडलर-आधारित बिल्ड के लिए (Unity WebGL रैपर, आदि)।
डाउनलोड करेंपूरा, न्यूनतम काम करने वाला गेम जो पूरे कॉन्ट्रैक्ट का इस्तेमाल करता है — यह सब एक्शन में देखने का सबसे तेज़ तरीका।
डाउनलोड करें