# GDevelop {#gdevelop}

ส่วนขยาย **ZokoGames** (`ZokoGames.json`) สำหรับ GDevelop 5 อยู่ใน `packages/sdk-engines/gdevelop` เป็นส่วนขยายอีเวนต์ธรรมดา: ทุกแอ็กชัน เงื่อนไข และนิพจน์เป็นอีเวนต์โค้ด JavaScript ขนาดเล็ก จึงใช้ได้ในพรีวิวและทุกการส่งออกเว็บโดยไม่ต้องมีไฟล์เพิ่ม ศัพท์อย่าง "midgame" และ "rewarded" อยู่ใน[อภิธานศัพท์](https://docs.zokogames.com/th/getting-started/glossary)

> [!NOTE]
> ปลั๊กอิน 1.7.2 ผ่านการตรวจสอบเมื่อ 2026-11-23 กับ GDevelop 5.6.287: ไฟล์ส่วนขยายนำเข้าใน GDevelop web editor ได้โดยไม่มีข้อผิดพลาด และการส่งออก HTML5 ของตัวอย่างด้วยตัวส่งออกของ GDevelop เองผ่านการตรวจสอบระบบจริง ปุ่มพรีวิวของเอดิเตอร์และการแก้ไขชีตอีเวนต์ด้วยมือยังไม่ได้ทดสอบ หากมีสิ่งใดล้มเหลว ให้ส่งเวอร์ชัน GDevelop และข้อความผิดพลาดที่ตรงตัวไปที่[การสนับสนุน](https://docs.zokogames.com/th/business/support)

## ติดตั้ง {#install}

ดาวน์โหลดส่วนขยาย GDevelop: [/sdk-engines/zokogames-gdevelop-1.7.2.zip](https://www.zokogames.com/sdk-engines/zokogames-gdevelop-1.7.2.zip) ภายในมี `ZokoGames.json` (สร้างจากโฟลเดอร์ `gdevelop` ในรีโพสิทอรี) โปรเจกต์ตัวอย่าง README และ changelog

[/sdk-engines/gdevelop.zip](https://www.zokogames.com/sdk-engines/gdevelop.zip) เป็นเวอร์ชันล่าสุดเสมอ เช็กซัม: [`/sdk-engines/SHA256SUMS`](https://www.zokogames.com/sdk-engines/SHA256SUMS) ดัชนีของแพ็กเกจเอนจินทั้งหมดพร้อมเวอร์ชัน ขนาด และ SHA-256: [`/sdk-engines/engines.json`](https://www.zokogames.com/sdk-engines/engines.json)

1. แตกไฟล์ที่ดาวน์โหลด ใน GDevelop เปิด **Project manager** แล้วไปที่ **Extensions > Import extension** และเลือก **`ZokoGames.json`** (ไม่ใช่ไฟล์ zip)
2. แอ็กชัน เงื่อนไข และนิพจน์จะปรากฏใต้ **ZokoGames** ในตัวแก้ไขอีเวนต์ นิพจน์เขียนในรูป `ZokoGames::UserName()`
3. รันแอ็กชัน **Initialize** ตอนเริ่มซีนแรก ส่วนขยายจะเพิ่ม `https://sdk.zokogames.com/zokogames-sdk-v1.js` ลงในหน้าเพจเอง คุณจึงไม่ต้องแก้ไฟล์ส่งออกใดๆ
4. ส่งออกเป็น HTML5 แล้วอัปโหลดไฟล์ zip

หากต้องการดูการทำงานก่อน ให้เปิด `examples/zokogames-example/game.json` จากไฟล์ที่ดาวน์โหลดแล้วพรีวิว ข้อความบนหน้าจอจะแสดงรายการตรวจสอบแต่ละข้อ

## เลือกเส้นทางไหน {#which-path}

| คุณคือ | ให้ทำดังนี้ |
| --- | --- |
| ผู้สร้างเกมด้วย GDevelop ที่มีเกมเสร็จแล้ว | นำเข้าส่วนขยาย เพิ่ม **Initialize** และอีเวนต์โฆษณาด้านล่าง ส่งออกเป็น HTML5 แล้วอัปโหลด ไม่ต้องใช้ JavaScript |
| คุ้นเคยกับอีเวนต์ JavaScript | เข้าถึง SDK ตัวเดียวกันได้จากอีเวนต์โค้ด JavaScript ในชื่อ `window.ZokoGames.SDK` เมื่อ **Initialize** เสร็จแล้ว |

## แท็ก ผลลัพธ์ และข้อผิดพลาด {#tags-results-and-errors}

<!-- search: headings-only -->

ทุกแอ็กชันแบบอะซิงโครนัสรับ **Tag** เป็นพารามิเตอร์แรก เมื่อการเรียกจบ **On request completed** (พร้อมแท็กนั้น) หรือ **On request failed** (พร้อมแท็กนั้น) จะเป็นจริงหนึ่งเฟรม ส่วน **On any request failed** เป็นจริงทุกครั้งที่ล้มเหลว ใช้หนึ่งแท็กต่อหนึ่งคำขอที่กำลังดำเนินอยู่

GDevelop รอแอ็กชันเหล่านี้: แอ็กชันที่อยู่หลังมันในอีเวนต์เดียวกันและอีเวนต์ย่อยของมันจะรันก็ต่อเมื่อคำขอจบแล้ว ทำให้สร้างลำดับง่ายๆ ได้สะดวก (นิพจน์ผลลัพธ์มีค่าใหม่อยู่แล้วในแอ็กชันถัดไป) แต่ให้แยกคำขอโฆษณาหรือการเรียกที่ช้าไว้ในอีเวนต์ของตัวเอง หากส่วนที่เหลือของอีเวนต์ไม่ควรรอ

| นิพจน์ | เนื้อหา |
| --- | --- |
| `ResultString` | ผลลัพธ์ล่าสุดเมื่อเป็นข้อความ: โทเคน ลิงก์คำเชิญ รายการที่บันทึกไว้ |
| `ResultNumber` | ผลลัพธ์ล่าสุดเป็นตัวเลข (บูลีนเป็น 1 และ 0; **Check ad blocker** ตั้งเป็น 1 เมื่อถูกบล็อก) |
| `ResultJSON` | ผลลัพธ์ล่าสุดเป็น JSON (หน้ารายชื่อเพื่อน คำตอบการเชื่อมบัญชี) |
| `ErrorCode`, `ErrorMessage`, `ErrorContainerId` | รายละเอียดของความล้มเหลวล่าสุด `ErrorContainerId` ถูกตั้งค่าสำหรับข้อผิดพลาดของแบนเนอร์ `ErrorDescription(code)` ให้ข้อความภาษาอังกฤษของรหัสนั้น |

## โฆษณาหยุดและปิดเสียงเกมให้เอง {#ads-pause-and-mute-the-game-for-you}

เมื่อโฆษณาเริ่ม ส่วนขยายจะปิดเสียงเกมทั้งหมดทันที ปล่อยให้ **On ad started** ทำงานหนึ่งเฟรม แล้วจึงหยุดเกมชั่วคราว เมื่อโฆษณาจบหรือล้มเหลว ส่วนขยายจะเล่นเกมต่อและคืนเสียงก่อนที่ **On ad finished** หรือ **On ad error** จะทำงาน การหยุดที่เกมของคุณทำเองจะไม่ถูกแตะต้อง ปิดแต่ละส่วนได้ด้วย **Pause the game during ads** และ **Mute the game during ads** หากเกมของคุณจัดการเอง โดยค่าเริ่มต้น เสียงเกมยังตามการตั้งค่าปิดเสียงของพอร์ทัลด้วย (**Follow the portal mute setting**)

## ชุดอีเวนต์ที่ใช้งานได้จริง {#a-working-set-of-events}

อีเวนต์ด้านล่างครอบคลุม init โฆษณา midgame โฆษณา rewarded การเริ่มและหยุดเกมเพลย์ การบันทึกและโหลด และคะแนนกระดานผู้นำ ใช้ตัวแปรซีน `Coins`, `Best` และ `RewardPending`

```
At the beginning of the scene (first scene)
    -> ZokoGames: Initialize (tag "init")

ZokoGames: On request completed ("init")
    -> ZokoGames: Get saved item (tag "load", key "best")
       ZokoGames: Loading stop (tag "ls")
    sub-event: ZokoGames::HasSavedItem("best") = 1
       -> Change Best: set to ToNumber(ZokoGames::SavedItem("best"))
ZokoGames: On request failed ("init")              // SDK missing or blocked: just start
    -> Change the scene to "Menu"

// Ads: the extension pauses and mutes; grant the reward only in On ad finished
ZokoGames: On ad finished
    + RewardPending = 1
    -> Add 10 to Coins ; Set RewardPending to 0
ZokoGames: On ad error
    -> Set RewardPending to 0

// Gameplay start/stop
Game scene: At the beginning of the scene (player can act)
    + ZokoGames: Is available
    -> ZokoGames: Gameplay start (tag "gs")
Game over (or pause menu opened)
    + ZokoGames: Is available
    -> ZokoGames: Gameplay stop (tag "gx")

// Midgame ad at a natural break, in its own event
Game over screen: At the beginning of the scene
    + ZokoGames: Is available
    -> ZokoGames: Request ad (type midgame, tag "mid")

// Rewarded ad
Reward button is clicked
    + ZokoGames: Is available
    -> Set RewardPending to 1 ; ZokoGames: Request ad (type rewarded, tag "rew")

// Save
Round ends and Score > Best
    -> Set Best to Score ; ZokoGames: Set saved item (tag "save", key "best", value ToString(Best))

// Leaderboard (signed-in players only; board enabled in the console)
Round ends
    + ZokoGames: Is available
    -> ZokoGames: Submit score (tag "score", encrypted "", score Score)
```

ชีตนี้ตั้งใจฝังกับดักไว้สองข้อ:

- **On request completed ("rew") ไม่ใช่ "โฆษณาจบ"** เมื่อโฆษณา unfilled ถูกบล็อก หรืออยู่ในคูลดาวน์ SDK จะส่ง **On ad error** และแอ็กชันก็ยังเสร็จสมบูรณ์ ดังนั้นให้มอบรางวัลใน **On ad finished** เท่านั้น เมื่อ SDK ถูกปิด แอ็กชันจะล้มเหลว (**On request failed**) และไม่มีอีเวนต์โฆษณาใดทำงาน เกมไม่เคยถูกหยุด จึงไม่มีอะไรต้องเล่นต่อ
- **`Submit score` ที่ค่า `encrypted` ว่าง** ใช้ได้เฉพาะกระดานที่ไม่มีคีย์เข้ารหัส (คะแนนธรรมดาถูกตรวจตามกฎของกระดาน) กระดานที่มีคีย์จะนับเฉพาะเพย์โหลดที่เข้ารหัสถูกต้อง ([กระดานผู้นำ](https://docs.zokogames.com/th/sdk/leaderboards#client-submission)) และส่วนขยายไม่มีตัวช่วยเข้ารหัส: ให้คำนวณคะแนนบนเซิร์ฟเวอร์ของคุณแล้วใช้ API ฝั่งเซิร์ฟเวอร์ หรือปล่อยกระดานให้ไม่มีคีย์สำหรับเกมสบายๆ ผู้เล่นที่ไม่ได้ลงชื่อเข้าใช้จะไม่ถูกจัดอันดับ

### การซื้อ {#purchases}

```
ZokoGames: On request completed ("init") + ZokoGames: Is store available
    -> Show the shop button ; ZokoGames: Get catalogue items (limit 50, offset 0, tag "cat")
ZokoGames: On request completed ("cat")
    -> Repeat ZokoGames::StoreItemCount() times: row with StoreItemName(i), StoreItemPrice(i), StoreItemCurrency(i)
Buy button is clicked
    -> ZokoGames: Buy item (ZokoGames::StoreItemSku(selected), tag "buy")
ZokoGames: On request completed ("buy")
    -> grant ZokoGames::PurchasedItemId() ; ZokoGames: Get purchase token (tag "tok")   // then send PurchaseToken to your server
ZokoGames: On request failed ("buy") + Last error is "purchaseCancelled"     -> (nothing)
ZokoGames: On request failed ("buy") + Last error is "userNotAuthenticated"  -> ZokoGames: Show login prompt (tag "login")
```

ตรวจสอบความเป็นเจ้าของบนเซิร์ฟเวอร์ของคุณ (ดู[การซื้อในเกม](https://docs.zokogames.com/th/sdk/purchases)) `StoreItemPrice` เป็น -1 เมื่อไม่มีราคา และ `InventoryQuantity` เป็น -1 เมื่อไม่นับจำนวน

## แอ็กชัน {#actions}

<!-- search: headings-only -->

| กลุ่ม | แอ็กชัน |
| --- | --- |
| เริ่มต้น | **Initialize** |
| โฆษณา | **Request ad** (midgame หรือ rewarded), **Check ad blocker**, **Pause the game during ads**, **Mute the game during ads**, **Follow the portal mute setting** |
| แบนเนอร์ | **Request banner** (id, ขนาด 728x90, 300x250, 320x50, 468x60 หรือ 320x100, x, y, กว้าง, สูง), **Request responsive banner** (id, x, y, กว้าง, สูง), **Clear banner**, **Clear all banners** |
| เกม | **Gameplay start**, **Gameplay stop**, **Loading start**, **Loading stop**, **Report loading progress** (0 ถึง 100), **Happytime**, **Report completed percentage**, **Set game context** (JSON), **Clear game context**, **Report chat message**, **Set screenshot provider**, **Answer screenshot** |
| ผู้เล่นหลายคน | **Update room**, **Set room public**, **Left room**, **Create invite link**, **Show invite button** และ **Hide invite button** (เลิกใช้แล้ว), **Show invite button (portal only)** และ **Hide invite button (portal only)** (SDK 1.7.0) |
| ผู้ใช้ | **Get user**, **List friends**, **Get user token**, **Show login prompt**, **Show account link prompt**, **Submit score** |
| ร้านค้า | **Get catalogue items**, **Get player inventory**, **Buy item**, **Consume item**, **Set sandbox**, **Get purchase token**, **Get payment provider user token** (เลิกใช้แล้ว) |
| เซฟบนคลาวด์ | **Get saved item**, **Set saved item**, **Remove saved item**, **Clear saved data**, **Mirror localStorage to cloud save**, **Stop mirroring localStorage** |
| ความสำเร็จ | **Unlock achievement** (คีย์), **List achievements** |
| การวิเคราะห์ | **Track event** (SDK 1.7.0), **Track order** |

สี่เหลี่ยมของแบนเนอร์อยู่ในหน่วยพิกเซลความละเอียดของเกม (ขนาดในคุณสมบัติโปรเจกต์) โดยมีจุดกำเนิดที่มุมซ้ายบน ส่วนขยายจะแปลงเป็นพิกัดบนแคนวาสที่ถูกปรับสเกล ขอแบนเนอร์เฉพาะในซีนเมนูเท่านั้น

## เงื่อนไข {#conditions}

<!-- search: headings-only -->

- สถานะ: **Is initialized**, **Is available** (เป็นเท็จเมื่อ SDK ถูกปิด), **Is QA tool**
- คำขอ: **On request completed**, **On request failed**, **On any request failed**, **Last error is** (รหัส)
- โฆษณา: **On ad started**, **On ad finished**, **On ad error**, **Is ad playing**
- การตั้งค่า: **On settings changed**, **Is mute requested**, **Is chat disabled**, **Is kids mode**
- ออฟไลน์: **On offline changed**, **Is offline**
- ผู้เล่นหลายคน: **Is instant multiplayer**, **On join room**
- ความสำเร็จ: **On achievement unlocked**
- บัญชี: **On auth changed**, **Is logged in**, **Is account available**
- ร้านค้า: **Is store available**
- ภาพหน้าจอและการสะท้อนพื้นที่เก็บข้อมูล: **On screenshot requested**, **On mirror error**

ทริกเกอร์ ("On ...") เป็นจริงหนึ่งเฟรม เมื่อมีสองรายการชนิดเดียวกันมาพร้อมกัน รายการที่สองจะถูกส่งในเฟรมถัดไป จึงไม่มีรายการใดหายไป

**โหมดเด็ก.** **Is kids mode** (`KidsMode`) เป็น true เมื่อเกมทำงานในโหมดเด็ก (เกมที่มีแฟล็กสำหรับเด็ก หรือผู้เล่นที่อยู่ในโหมดเด็ก) เมื่อนั้นให้ซ่อนแชต ห้อง คำชวนให้ลงชื่อเข้าใช้ และหน้าจอร้านค้า พอร์ทัลที่ไม่ส่งฟิลด์นี้จะให้ค่า false ดังนั้นให้เคารพ **Is chat disabled** ต่อไปด้วย หากต้องการทดสอบ ให้เพิ่ม `?kidsMode=true` ในที่อยู่หน้าเว็บในโหมดโลคอล ดู[โหมดเด็ก](https://docs.zokogames.com/th/guides/kids-mode)

## นิพจน์ {#expressions}

<!-- search: headings-only -->

`Environment`, `SdkVersion`, `GameId`, `MuteAudio`, `DisableChat`, `KidsMode`, `InviteParam(key)`, `InviteParamsJSON`, `UserName`, `UserPictureUrl`, `UserId` (อย่าเชื่อถือบนเซิร์ฟเวอร์ ให้ตรวจสอบโทเคน), `UserToken`, `FriendCount`, `FriendsTotal`, `FriendsHasMore`, `FriendName(i)`, `FriendId(i)`, `FriendPictureUrl(i)`, `Locale`, `CountryCode`, `DeviceType`, `SavedItem(key)`, `HasSavedItem(key)`, `ErrorCodes(module)` (รหัสคั่นด้วยจุลภาคสำหรับ `ad`, `banner`, `user`, `data`, `store`, `room` หรือ `general`), `ErrorDescription(code)`, `ResultJSON`, `ResultString`, `ResultNumber`, `ErrorCode`, `ErrorMessage`, `ErrorContainerId`, `MirrorErrorCode`, `MirrorErrorMessage` นิพจน์ร้านค้า `StoreItemCount`, `StoreItemSku(i)`, `StoreItemName(i)`, `StoreItemDescription(i)`, `StoreItemImageUrl(i)`, `StoreItemPrice(i)`, `StoreItemCurrency(i)`, `StoreItemConsumable(i)`, `InventoryCount`, `InventorySku(i)`, `InventoryName(i)`, `InventoryDescription(i)`, `InventoryImageUrl(i)`, `InventoryQuantity(i)`, `PurchasedItemId`, `PurchaseToken`, `XsollaUserToken` (ชื่อเก่าที่เลิกใช้แล้วของโทเคนการซื้อ) และนิพจน์ความสำเร็จ `AchievementCount`, `AchievementKeyAt(i)`, `AchievementNameAt(i)`, `AchievementDescriptionAt(i)`, `AchievementPointsAt(i)`, `AchievementUnlockedAt(i)`, `AchievementIsUnlockedAt(i)` (1 หรือ 0), `LastUnlockReason`, `LastAchievementKey`, `LastAchievementName` และ `LastAchievementPoints` ให้รัน **List achievements** ก่อนนิพจน์ `...At(i)` ส่วน **Unlock achievement** จะเติมค่าในกลุ่ม `LastAchievement...` สำหรับแขกและคีย์ที่ไม่รู้จัก แอ็กชันยังเสร็จสมบูรณ์ และ `LastUnlockReason` เป็น `guest`, `not_found`, `not_live`, `rate_limited` หรือ `error` ดู[ความสำเร็จ](https://docs.zokogames.com/th/sdk/achievements)

`SavedItem(key)` อ่านจาก SDK โดยตรงเมื่อ **Initialize** เสร็จแล้ว ค่าที่บันทึกที่ใดก็ตามในเกมจึงมองเห็นได้ทันที

## อีเวนต์ JavaScript {#javascript-events}

```js
// JavaScript code event, after the "init" request completed.
const SDK = window.ZokoGames.SDK;
SDK.user.getUser().then((user) => {
  runtimeScene.getVariables().get("PlayerName").setString(user ? user.username : "guest");
});
```

## ช่องข้อมูลห้อง {#room-data-channel}

เพิ่มใน SDK 1.3.0 ช่องข้อมูลห้องช่วยให้ผู้เล่นในห้องเดียวกันแลกเปลี่ยนข้อความ JSON ขนาดเล็กและแชร์สถานะเล็กๆ ที่มีเพียงโฮสต์เท่านั้นที่เขียนได้ เกมผู้เล่นหลายคนแบบง่ายจึงไม่ต้องมีเซิร์ฟเวอร์ของตัวเอง ช่องนี้ใช้กับข้อมูลเกม ไม่ใช่แชตข้อความ ใช้งานได้หลัง **Update room** (หรือหลังเข้าร่วมจากคำเชิญ) และสิ้นสุดเมื่อ **Left room** ต้องมีผู้เล่นที่ลงชื่อเข้าใช้และพอร์ทัลที่เปิดเรียลไทม์ไว้ (มิฉะนั้นได้ `roomUnavailable`) มีขีดจำกัดดังนี้: 8 KB ต่อข้อความหรือแพตช์ 20 ข้อความต่อวินาที สถานะ 64 KB และคีย์สถานะยาว 1 ถึง 40 ตัวอักษรจาก `A-Z a-z 0-9 _ . : -` บนพอร์ทัลข้อความจะไม่ถูกส่งกลับไปยังผู้ส่ง ผู้เล่นคนแรกในห้องคือโฮสต์ กฎฉบับเต็มและรหัสข้อผิดพลาด (`notInRoom`, `notHost`, `payloadTooLarge`, `stateTooLarge`, `unknownMember`, `rateLimited`, `roomUnavailable`) อยู่ใน[โมดูล game](https://docs.zokogames.com/th/sdk/game#room-data-channel)และ[คู่มือผู้เล่นหลายคน](https://docs.zokogames.com/th/guides/multiplayer-invites#6-exchange-game-data-in-the-room)

พารามิเตอร์ข้อความและค่ารับเป็นข้อความ: JSON ที่ถูกต้อง (`{"x":1}`, `5`, `true`) จะส่งเป็นค่า JSON นั้น ส่วนอย่างอื่นส่งเป็นข้อความธรรมดา บน `localhost` โหมดโลคอลของ SDK ทำให้แท็บเบราว์เซอร์สองแท็บที่เข้าร่วมรหัสห้องเดียวกันทำงานเหมือนผู้เล่นสองคน

| ชนิด | ฟังก์ชัน |
| --- | --- |
| แอ็กชัน | **Send room message** (tag, data), **Send room message to member** (tag, member id, data), **Set room state key** (tag, key, value; เฉพาะโฮสต์), **Remove room state key** (tag, key; เฉพาะโฮสต์) |
| ทริกเกอร์ | **On room message**, **On room state changed**, **On room members changed**, **On room host changed**, **On room left** (SDK 1.7.0), **On room error** |
| เงื่อนไข | **Is room host** |
| นิพจน์ข้อความ | `RoomMessageData`, `RoomMessageFrom`, `RoomMessageDirect`, `RoomMessageSeq`, `RoomMessageValue(key)` |
| นิพจน์สถานะ | `RoomStateJSON`, `RoomStateValue(key)`, `RoomStateChangedKeys`, `RoomStateChangedBy`, `RoomStateRev` |
| นิพจน์สมาชิก | `RoomMemberCount`, `RoomMemberIdAt(i)`, `RoomMemberNameAt(i)`, `RoomMemberPictureUrlAt(i)`, `RoomHostId`, `RoomSelfId` |
| นิพจน์การออกจากห้อง | `RoomLeftReason` (`left`, `kicked`, `closed`, `disconnected`), `RoomLeftRoomId` (สำหรับ **On room left**, SDK 1.7.0) |
| นิพจน์ข้อผิดพลาด | `RoomErrorCode`, `RoomErrorMessage` (สำหรับทริกเกอร์ข้อผิดพลาดของห้อง; ความล้มเหลวของคำขอยังคงใช้ **On request failed**) |

```
ZokoGames: On room host changed
  + ZokoGames: Is room host        -> ZokoGames: Set room state key (key "turn", value "X", tag "turn")
Cell is clicked                    -> ZokoGames: Send room message ("{""cell"":" + ToString(Cell) + "}", tag "move")
ZokoGames: On room message         -> place a mark at ZokoGames::RoomMessageValue("cell")
ZokoGames: On room state changed   -> Text: set to ZokoGames::RoomStateValue("turn")
```

## การตั้งค่าส่งออกที่สำคัญบนเว็บ {#export-settings-that-matter-on-the-web}

- **ส่งออกเป็น HTML5** (โฟลเดอร์ในเครื่อง) แล้วบีบอัด zip **เนื้อหา**ของโฟลเดอร์ส่งออกเพื่อให้ `index.html` อยู่ที่รากของไฟล์
- **ไม่ต้องบีบอัดล่วงหน้า** GDevelop ขอชื่อไฟล์ธรรมดา ให้อัปโหลดไฟล์ที่ส่งออกตามที่เป็น ขีดจำกัด: 1,500 ไฟล์ 250 MB เมื่อแตกไฟล์ ดาวน์โหลดเริ่มต้นราว 50 MB (20 MB สำหรับมือถือ) บีบอัดรูปภาพและเสียง และดู[เฟรมแรกให้เร็ว](https://docs.zokogames.com/th/guides/first-frame)
- **การปรับขนาดแคนวาส** ขนาดเฟรมเปลี่ยนตามเต็มจอและการหมุน ตั้งค่าความละเอียดของเกมให้ปรับตาม (Project properties > Resolution and rendering) เพื่อให้ซีนพอดีกับ[ความละเอียดที่กำหนด](https://docs.zokogames.com/th/requirements/gameplay)ทุกแบบ
- **การปลดล็อกเสียง** เบราว์เซอร์จะระงับเสียงไว้จนกว่าจะคลิกหรือแตะครั้งแรก ให้เริ่มเพลงจากปุ่ม "แตะเพื่อเล่น" ไม่ใช่ตอนเริ่มซีนแรก
- **เต็มจอ** ควรใช้ปุ่มเต็มจอบนแถบเฟรมของพอร์ทัล อย่าเพิ่มปุ่มที่แย่งหน้าที่กัน
- **การโหลด** ให้รัน **Loading start** ในซีนแรกของคุณ **Report loading progress** ขณะโหลดทรัพยากร และ **Loading stop** เมื่อเริ่มเล่นได้

## รายงานแชท ภาพหน้าจอ และการสะท้อนพื้นที่เก็บข้อมูล {#chat-reports-screenshots-and-storage-mirror}

ตั้งแต่ SDK 1.4.0: แอ็กชัน **Report chat message** (ชื่อ ข้อความ เหตุผล รวมถึง user id, room id และ JSON บริบทแบบไม่บังคับ), แอ็กชัน **Set screenshot provider** และ **Answer screenshot** พร้อมเงื่อนไข **On screenshot requested** และ **Mirror localStorage to cloud save** พร้อมเงื่อนไข **On mirror error** เมื่อเปิดตัวส่งภาพหน้าจอ (screenshot provider) ไว้และเกมไม่ตอบภายใน 1.5 วินาที แคนวาสของเกมจะถูกส่งไปแทน แอ็กชัน **Storage** ของ GDevelop เก็บข้อมูลไว้ใน IndexedDB การสะท้อนจึงไม่คัดลอกข้อมูลนั้น ให้ใช้แอ็กชันเซฟบนคลาวด์สำหรับการบันทึกเหล่านั้น

## SDK 1.7.0 {#sdk-170}

- **Track event** (ชื่อ, JSON ของพารามิเตอร์): ส่งแล้วไม่ต้องรอผล ชื่อ: ตัวอักษรพิมพ์เล็กหนึ่งตัว ตามด้วยตัวอักษรพิมพ์เล็ก ตัวเลข หรือขีดล่าง ยาวไม่เกิน 40 ตัวอักษร พารามิเตอร์: ออบเจ็กต์ JSON แบบแบนที่ไม่บังคับ มีค่าข้อความ ตัวเลข หรือใช่/ไม่ใช่ไม่เกิน 10 ค่า
- **On room left** พร้อม `RoomLeftReason` และ `RoomLeftRoomId`: พอร์ทัลยุติสมาชิกภาพในห้องของผู้เล่นโดยที่เกมไม่ได้ร้องขอ (ถูกเตะ ห้องถูกปิด การเชื่อมต่อหลุด) แฟล็กโฮสต์จะถูกล้าง
- **Show invite button (portal only)** และ **Hide invite button (portal only)**: ปุ่มเชิญของพอร์ทัลโดยไม่เปลี่ยนว่าห้องเข้าร่วมได้หรือไม่ ลิงก์อยู่ใน `ResultString`
- `data.mirrorIndexedDB` ไม่ใช่แอ็กชัน: ต้องรันในหน้าเพจก่อนที่เกมจะอ่านไฟล์ของตัวเอง จึงให้เรียก `ZokoSDK.data.mirrorIndexedDB` จากสคริปต์ของหน้าเพจก่อนเกมโหลด

## กฎของโฆษณา {#ad-rules}

ไม่มี preroll: เกมของคุณขอโฆษณาก่อนเกมเริ่มไม่ได้ Midgame เป็น interstitial ชนิดเดียว ดังนั้น interstitial หรือคอมเมอร์เชียลเบรกจากแพลตฟอร์มอื่นจึงกลายเป็นโฆษณา midgame (**Request ad** ด้วยชนิด `midgame`) ชนิดอื่นมีเพียง `rewarded` ในโหมดโลคอล (ทดสอบบน `localhost` นอกพอร์ทัล) คำขอ midgame จะล้มเหลวด้วย **On ad error** พร้อม `adCooldown` จนกว่าเกมของคุณจะเรียกแอ็กชัน **Gameplay start** หรือเวลาที่หน้าเพจมองเห็นครบ 30 วินาที บนพอร์ทัล โฆษณา midgame แรกก็ต้องเรียกแอ็กชัน **Gameplay start** ก่อนเช่นกัน ดังนั้นให้เรียกเมื่อผู้เล่นได้ควบคุม (เกมที่ไม่เคยเรียกจะได้โฆษณา midgame 30 วินาทีหลังเริ่มเล่น) โฆษณา rewarded ไม่ถูกหน่วงด้วยเรื่องนี้ รายละเอียด: [เอกสารอ้างอิงโฆษณา](https://docs.zokogames.com/th/sdk/ads#gameplay-first) และ[คู่มือการสร้างรายได้จากโฆษณา](https://docs.zokogames.com/th/guides/ad-monetisation)

## ทดสอบในเครื่อง {#test-locally}

ไม่มีตัวจำลองแยกต่างหาก เมื่อโฮสต์ของหน้าเพจเป็น `localhost`, `127.0.0.1` หรือชื่อ `*.localhost` JavaScript SDK จะรัน[โหมดโลคอล](https://docs.zokogames.com/th/getting-started/local-testing)ของตัวเอง: โอเวอร์เลย์สามวินาทีสำหรับโฆษณาแต่ละครั้ง ผู้เล่นปลอม เซฟบนคลาวด์ใน `localStorage` และร้านค้าทดสอบสามรายการ อีเวนต์ชุดเดียวกับบนพอร์ทัลจึงทำงาน บนโฮสต์อื่นสภาพแวดล้อมคือ `disabled` และ **Is available** เป็นเท็จ

- พรีวิวของ GDevelop รันจากเว็บเซิร์ฟเวอร์ในเครื่องขนาดเล็ก หาก `Environment` เป็น `disabled` ที่นั่น (ที่อยู่เครือข่ายแทน `localhost`) ให้ส่งออกโปรเจกต์แล้วเสิร์ฟโฟลเดอร์จาก `localhost` หรือเปิดหน้าเพจด้วย `?useLocalSdk=true`
- คำขอ midgame ครั้งที่สองภายในสามนาทีจะล้มเหลวด้วย `adCooldown` (ทริกเกอร์ **On ad error**): เป็นกฎจริง อีเวนต์ของคุณจึงต้องรับมือได้
- สวิตช์ที่มีประโยชน์: `?sdk_debug=true`, `?ad_response=unfilled`, `?user_response=logged_out`
- จากนั้นเปิด[เครื่องมือพรีวิว](https://www.zokogames.com/th/preview)ด้วยที่อยู่ในเครื่องของคุณ แล้วดูเช็กลิสต์ติ๊กทีละข้อ

## API

### `init`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `init` | แอ็กชัน `Initialize`; เงื่อนไข `IsInitialized`, `IsAvailable` |
| `environment` | นิพจน์ `Environment` |
| `isQaTool` | เงื่อนไข `IsQaTool` |

### `ad.*`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `ad.requestAd` | แอ็กชัน `RequestAd`; เงื่อนไข `OnAdStarted`, `OnAdFinished`, `OnAdError`, `IsAdPlaying` |
| `ad.requestAd.adStarted` | เงื่อนไข `OnAdStarted`; `IsAdPlaying` true |
| `ad.requestAd.adFinished` | เงื่อนไข `OnAdFinished` |
| `ad.requestAd.adError` | เงื่อนไข `OnAdError`; นิพจน์ `ErrorCode` |
| `ad.hasAdblock` | แอ็กชัน `HasAdblock` |

### `banner.*`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `banner.requestBanner` | แอ็กชัน `RequestBanner` |
| `banner.requestResponsiveBanner` | แอ็กชัน `RequestResponsiveBanner` |
| `banner.clearBanner` | แอ็กชัน `ClearBanner` |
| `banner.clearAllBanners` | แอ็กชัน `ClearAllBanners` |

### `game.*`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `game.settings` | นิพจน์ `MuteAudio`, `DisableChat`, `KidsMode`; เงื่อนไข `IsMuteRequested`, `IsChatDisabled`, `IsKidsMode` |
| `game.addSettingsChangeListener` | เงื่อนไข `OnSettingsChanged` |
| `game.gameplayStart` | แอ็กชัน `GameplayStart` |
| `game.gameplayStop` | แอ็กชัน `GameplayStop` |
| `game.loadingStart` | แอ็กชัน `LoadingStart` |
| `game.loadingStop` | แอ็กชัน `LoadingStop` |
| `game.loadingProgress` | แอ็กชัน `LoadingProgress` |
| `game.happytime` | แอ็กชัน `Happytime` |
| `game.reportGameCompletedPercentage` | แอ็กชัน `ReportCompleted` |
| `game.reportChat` | แอ็กชัน `ReportChat` |
| `game.onScreenshotRequest` | แอ็กชัน `SetScreenshotProvider`, `AnswerScreenshot`; เงื่อนไข `OnScreenshotRequested` |
| `game.setGameContext` | แอ็กชัน `SetGameContext` |
| `game.clearGameContext` | แอ็กชัน `ClearGameContext` |
| `game.isInstantMultiplayer` | เงื่อนไข `IsInstantMultiplayer` |
| `game.isInstantJoin` | เงื่อนไข `IsInstantMultiplayer` |
| `game.isOffline` | เงื่อนไข `IsOffline` |
| `game.gameId` | นิพจน์ `GameId` |
| `game.addOfflineListener` | เงื่อนไข `OnOfflineChanged` |
| `game.updateRoom` | แอ็กชัน `UpdateRoom`; แอ็กชัน `SetRoomPublic` |
| `game.leftRoom` | แอ็กชัน `LeftRoom` |
| `game.addJoinRoomListener` | เงื่อนไข `OnJoinRoom` |
| `game.inviteParams` | นิพจน์ `InviteParamsJSON`, `InviteParam` |
| `game.inviteLink` | แอ็กชัน `InviteLink` |
| `game.getInviteParam` | นิพจน์ `InviteParam` |
| `game.showInviteButton` | แอ็กชัน `ShowInviteButton`; `ShowInviteButtonPortalOnly` (`{ portalOnly: true }`) |
| `game.hideInviteButton` | แอ็กชัน `HideInviteButton`; `HideInviteButtonPortalOnly` (`{ portalOnly: true }`) |
| `game.room` | แอ็กชัน `SendRoomMessage`, `SendRoomMessageTo`, `SetRoomStateKey`, `RemoveRoomStateKey`; เงื่อนไข `OnRoomMessage`, `OnRoomStateChanged`, `OnRoomMembersChanged`, `OnRoomHostChanged`, `OnRoomError`, `IsRoomHost` |
| `game.room.send` | แอ็กชัน `SendRoomMessage`, `SendRoomMessageTo` |
| `game.room.onMessage` | เงื่อนไข `OnRoomMessage`; นิพจน์ `RoomMessageData`, `RoomMessageFrom`, `RoomMessageDirect`, `RoomMessageSeq`, `RoomMessageValue` |
| `game.room.addMessageListener` | เงื่อนไข `OnRoomMessage` |
| `game.room.setState` | แอ็กชัน `SetRoomStateKey`, `RemoveRoomStateKey` |
| `game.room.getState` | นิพจน์ `RoomStateJSON`, `RoomStateValue` |
| `game.room.onState` | เงื่อนไข `OnRoomStateChanged`; นิพจน์ `RoomStateChangedKeys`, `RoomStateChangedBy`, `RoomStateRev` |
| `game.room.addStateListener` | เงื่อนไข `OnRoomStateChanged` |
| `game.room.members` | นิพจน์ `RoomMemberCount`, `RoomMemberIdAt`, `RoomMemberNameAt`, `RoomMemberPictureUrlAt` |
| `game.room.onMembers` | เงื่อนไข `OnRoomMembersChanged` |
| `game.room.addMembersListener` | เงื่อนไข `OnRoomMembersChanged` |
| `game.room.isHost` | เงื่อนไข `IsRoomHost` |
| `game.room.onHostChange` | เงื่อนไข `OnRoomHostChanged`; นิพจน์ `RoomHostId` |
| `game.room.addHostChangeListener` | เงื่อนไข `OnRoomHostChanged` |
| `game.room.selfId` | นิพจน์ `RoomSelfId` |
| `game.room.onError` | เงื่อนไข `OnRoomError`; นิพจน์ `RoomErrorCode`, `RoomErrorMessage` |
| `game.room.addErrorListener` | เงื่อนไข `OnRoomError` |
| `game.room.addLeftListener` | เงื่อนไข `OnRoomLeft`; นิพจน์ `RoomLeftReason`, `RoomLeftRoomId` |

### `user.*`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `user.isUserAccountAvailable` | เงื่อนไข `IsAccountAvailable` |
| `user.systemInfo` | นิพจน์ `Locale`, `CountryCode`, `DeviceType` |
| `user.getUser` | แอ็กชัน `GetUser`; นิพจน์ `UserName`, `UserPictureUrl`, `UserId`; เงื่อนไข `IsLoggedIn` |
| `user.listFriends` | แอ็กชัน `ListFriends`; นิพจน์ `FriendCount`, `FriendsTotal`, `FriendsHasMore`, `FriendName`, `FriendId`, `FriendPictureUrl` |
| `user.getUserToken` | แอ็กชัน `GetUserToken`; นิพจน์ `UserToken` |
| `user.showAuthPrompt` | แอ็กชัน `ShowAuthPrompt` |
| `user.addAuthListener` | เงื่อนไข `OnAuthChanged` |
| `user.showAccountLinkPrompt` | แอ็กชัน `ShowAccountLinkPrompt` |
| `user.submitScore` | แอ็กชัน `SubmitScore` |
| `user.getXsollaUserToken` | แอ็กชัน `GetXsollaUserToken`; นิพจน์ `XsollaUserToken` |

### `data.*`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `data.getItem` | แอ็กชัน `GetItem`; นิพจน์ `SavedItem`, `HasSavedItem` |
| `data.setItem` | แอ็กชัน `SetItem` |
| `data.removeItem` | แอ็กชัน `RemoveItem` |
| `data.clear` | แอ็กชัน `ClearData` |
| `data.mirrorLocalStorage` | แอ็กชัน `MirrorLocalStorage`, `StopMirrorLocalStorage`; เงื่อนไข `OnMirrorError`; นิพจน์ `MirrorErrorCode`, `MirrorErrorMessage` |

### `store.*`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `store.isAvailable` | เงื่อนไข `IsStoreAvailable` |
| `store.getCatalogItems` | แอ็กชัน `GetCatalogItems`; นิพจน์ `StoreItemCount`, `StoreItemSku`, `StoreItemName`, `StoreItemDescription`, `StoreItemImageUrl`, `StoreItemPrice`, `StoreItemCurrency`, `StoreItemConsumable` |
| `store.getPlayerInventory` | แอ็กชัน `GetPlayerInventory`; นิพจน์ `InventoryCount`, `InventorySku`, `InventoryName`, `InventoryDescription`, `InventoryImageUrl`, `InventoryQuantity` |
| `store.buyItem` | แอ็กชัน `BuyItem`; นิพจน์ `PurchasedItemId` |
| `store.consumeItem` | แอ็กชัน `ConsumeItem` |
| `store.getPurchaseToken` | แอ็กชัน `GetPurchaseToken`; นิพจน์ `PurchaseToken` |
| `store.setSandbox` | แอ็กชัน `SetSandbox` |

### `achievements.*`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `achievements.list` | แอ็กชัน `ListAchievements`; นิพจน์ `AchievementCount`, `AchievementKeyAt`, `AchievementNameAt`, `AchievementDescriptionAt`, `AchievementPointsAt`, `AchievementUnlockedAt`, `AchievementIsUnlockedAt` |
| `achievements.unlock` | แอ็กชัน `UnlockAchievement`; นิพจน์ `LastUnlockReason`, `LastAchievementKey`, `LastAchievementName`, `LastAchievementPoints` |
| `achievements.onUnlock` | เงื่อนไข `OnAchievementUnlocked` |

### `analytics.*`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `analytics.track` | แอ็กชัน `TrackEvent` |
| `analytics.trackOrder` | แอ็กชัน `TrackOrder` |

### `constants`

<!-- search: headings-only -->

| JavaScript | GDevelop |
| --- | --- |
| `ERROR_CODES` | นิพจน์ `ErrorCodes`; เงื่อนไข `LastErrorIs` |
| `ERROR_CODE_DESCRIPTIONS` | นิพจน์ `ErrorDescription` |
| `SDK_VERSION` | นิพจน์ `SdkVersion` |

## ข้อควรระวังที่พบบ่อย {#known-pitfalls}

<!-- search: headings-only -->

- **นำเข้าไม่ได้** ให้นำเข้า `ZokoGames.json` ไม่ใช่ไฟล์ zip
- **เงื่อนไขไม่เคยเป็นจริง** แท็กใน **On request completed** ต้องเท่ากับแท็กที่ส่งให้แอ็กชัน และควรมีเพียงหนึ่งคำขอต่อแท็กที่กำลังดำเนินอยู่
- **แอ็กชันรันแต่ไม่เกิดอะไรขึ้น** ให้รัน **Initialize** ก่อนและรอให้เสร็จ
- **`sdkNotLoaded`** ออฟไลน์หรือโฮสต์ SDK ถูกบล็อก พรีวิวต้องเข้าถึงอินเทอร์เน็ตเพื่อโหลดสคริปต์
- **แอ็กชันหลังคำขอโฆษณารันช้า** GDevelop รอคำขอ ให้เริ่มโฆษณาในอีเวนต์ของตัวเอง
- **แบนเนอร์อยู่ผิดที่** สี่เหลี่ยมอยู่ในพิกเซลความละเอียดของเกม จุดกำเนิดอยู่มุมซ้ายบน

## ถัดไป {#next}

- ตรวจสอบบิลด์ของคุณตาม[กฎการตรวจสอบบิลด์](https://docs.zokogames.com/th/requirements/build-validation)และ[เช็กลิสต์การเปิดตัว](https://docs.zokogames.com/th/requirements/checklist)
- อัปโหลดและเผยแพร่: [ขั้นตอนการส่งเกม](https://docs.zokogames.com/th/getting-started/submission-walkthrough)
- เอนจินอื่นและกฎที่ใช้ร่วมกัน: [ภาพรวมเอนจิน](https://docs.zokogames.com/th/engines/overview)
