Skip to content

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.

js
const result = await gameTegra.custom('myCustomFunction', {
  param1: 'value1',
  param2: 42
})
csharp
var result = await gameTegra.custom<MyResponseType>("myCustomFunction",
    gameTegra.@params("param1", "value1", "param2", 42)
);
gdscript
var result = await gameTegra.custom("myCustomFunction", {
    "param1": "value1",
    "param2": 42
})

Parameters:

FieldTypeRequiredDescription
functionNamestringYesBackend function name
paramsobjectNoParameters to send
settingsobjectNo(JS only) Timeout and behavior options

Settings (JS Only)

js
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 with custom<T>.
  • Godot: typically returned as Variant / Dictionary.

setMethodMap (JS Only)

Updates aliases used by callGameMethod().

js
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.

js
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

js
await gameTegra.callGameMethod('createRoom', { maxPlayers: 4 })

joinRoom

Joins an existing room. Details: joinRoom

js
await gameTegra.callGameMethod('joinRoom', { roomId: 'room-abc-123' })

leaveRoom

Leaves the active room. Details: leaveRoom

js
await gameTegra.callGameMethod('leaveRoom')

quickMatch

Starts quick matchmaking. Details: quickMatch

js
await gameTegra.callGameMethod('quickMatch', { gameMode: 'ranked' })

getScore

Gets player score. Details: getScore

js
await gameTegra.callGameMethod('getScore')

saveData

Saves game data. Details: saveData

js
await gameTegra.callGameMethod('saveData', { level: 5, coins: 1200 })

loadData

Loads saved data. Details: loadData

js
await gameTegra.callGameMethod('loadData', { key: 'player_progress' })

showAd

Shows an ad. Details: showAd

js
await gameTegra.callGameMethod('showAd', { type: 'rewarded' })

createLeaderboard

Creates leaderboard. Details: createLeaderboard

js
await gameTegra.callGameMethod('createLeaderboard', {
  name: 'high_scores',
  sortOrder: 'desc'
})

getLeaderboard

Fetches leaderboard data. Details: getLeaderboard

js
await gameTegra.callGameMethod('getLeaderboard', { name: 'high_scores', limit: 10 })

updateLeaderboard

Updates leaderboard score. Details: updateLeaderboard

js
await gameTegra.callGameMethod('updateLeaderboard', { name: 'high_scores', score: 9500 })

Custom Game Method Examples

Use custom() or callGameMethod() for your own backend methods.

getInventory

js
const inventory = await gameTegra.custom('getInventory')

useItem

js
await gameTegra.custom('useItem', {
  itemId: 'health_potion',
  quantity: 1
})

buyItem

js
await gameTegra.custom('buyItem', {
  itemId: 'sword_of_fire',
  currency: 'coins'
})

Which one to use?

  • Built-in SDK method exists: use callGameMethod('createRoom', ...) or direct gameTegra.createRoom(...).
  • Backend-specific method: use custom('myFunction', params).
  • Prefer readable aliases in JS: use setMethodMap() + callGameMethod().