Game Method (Custom API)
This page explains the game method invocation layer in the SDK: custom(), setMethodMap(), and callGameMethod().
custom
Calls any backend-defined function directly.
const result = await gameTegra.custom('myCustomFunction', {
param1: 'value1',
param2: 42
})var result = await gameTegra.custom<MyResponseType>("myCustomFunction",
gameTegra.@params("param1", "value1", "param2", 42)
);var result = await gameTegra.custom("myCustomFunction", {
"param1": "value1",
"param2": 42
})Parameters:
| Field | Type | Required | Description |
|---|---|---|---|
| functionName | string | Yes | Backend function name |
| params | object | No | Parameters to send |
| settings | object | No | (JS only) Timeout and behavior options |
Settings (JS Only)
const result = await gameTegra.custom('slowFunction', { data: 'test' }, {
timeout: 120,
activeTimeout: true
})Return Type
Return type depends on backend implementation.
JavaScript: returns backend data as-is.Unity: deserialized withcustom<T>.Godot: typically returned asVariant/Dictionary.
setMethodMap (JS Only)
Updates aliases used by callGameMethod().
gameTegra.setMethodMap({
...gameTegra.methodMap,
myCustom: 'myBackendFunction'
})callGameMethod (JS Only)
Invokes a method via alias map. If alias is missing, it is treated as a direct method name.
const room = await gameTegra.callGameMethod('createRoom', { maxPlayers: 4 })
const inventory = await gameTegra.callGameMethod('myCustom', { userId: 'u1' })Default Game Method Aliases
The following aliases are included in the default method map and can be called one by one.
createRoom
Creates a new room. Details: createRoom
await gameTegra.callGameMethod('createRoom', { maxPlayers: 4 })joinRoom
Joins an existing room. Details: joinRoom
await gameTegra.callGameMethod('joinRoom', { roomId: 'room-abc-123' })leaveRoom
Leaves the active room. Details: leaveRoom
await gameTegra.callGameMethod('leaveRoom')quickMatch
Starts quick matchmaking. Details: quickMatch
await gameTegra.callGameMethod('quickMatch', { gameMode: 'ranked' })getScore
Gets player score. Details: getScore
await gameTegra.callGameMethod('getScore')saveData
Saves game data. Details: saveData
await gameTegra.callGameMethod('saveData', { level: 5, coins: 1200 })loadData
Loads saved data. Details: loadData
await gameTegra.callGameMethod('loadData', { key: 'player_progress' })showAd
Shows an ad. Details: showAd
await gameTegra.callGameMethod('showAd', { type: 'rewarded' })createLeaderboard
Creates leaderboard. Details: createLeaderboard
await gameTegra.callGameMethod('createLeaderboard', {
name: 'high_scores',
sortOrder: 'desc'
})getLeaderboard
Fetches leaderboard data. Details: getLeaderboard
await gameTegra.callGameMethod('getLeaderboard', { name: 'high_scores', limit: 10 })updateLeaderboard
Updates leaderboard score. Details: updateLeaderboard
await gameTegra.callGameMethod('updateLeaderboard', { name: 'high_scores', score: 9500 })Custom Game Method Examples
Use custom() or callGameMethod() for your own backend methods.
getInventory
const inventory = await gameTegra.custom('getInventory')useItem
await gameTegra.custom('useItem', {
itemId: 'health_potion',
quantity: 1
})buyItem
await gameTegra.custom('buyItem', {
itemId: 'sword_of_fire',
currency: 'coins'
})Which one to use?
- Built-in SDK method exists: use
callGameMethod('createRoom', ...)or directgameTegra.createRoom(...). - Backend-specific method: use
custom('myFunction', params). - Prefer readable aliases in JS: use
setMethodMap()+callGameMethod().