## Game > Gamebase > JavaScript SDK User Guide > ETC
Additional functions provided by Gamebase are described as below:
Similar to the Maintenance popup, the language used by the device will be displayed as the Gamebase language.
However, there are games that may use a language different from the device language with separate options. For example, if the language configured for the device is English and you changed the game language to Japanese, the language displayed will be still English, even though you might want to see Japanese on the Gamebase screen.
For this, Gamebase provides a Display Language feature for applications that want to use a language that is not the language configured by the device for Gamebase.
Gamebase displays its messages in the language set in Display Language. The language code entered for Display Language should be one of the codes listed in the table (**Types of language codes supported by Gamebase) below:
[Caution]
- Use Display Language only when you want to change the language displayed in Gamebase to a language other than the one configured by the device.
- Display Language Code is a case-sensitive value in the form of ISO-639. There could be a problem if it is configured as a value such as 'EN' or 'zh-cn'.
- If the value entered as Display Language Code does not exist in the table (**Types of language codes supported by Gamebase) below, Display Language Code is automatically set to English (en) by default.
[Note]
- As the client messages of Gamebase include only English (en), Korean (ko), and Japanese (ja), if you try to set a language other than English (en), Korean (ko), or Japanese (ja), even though the language code might be listed in the table below, the value is automatically set to English (en) by default.
- You can manually add a language set that is not included in the Gamebase client. See the Add New Language Set section.
Code | Name |
---|---|
de | German |
en | English |
es | Spanish |
fi | Finnish |
fr | French |
id | Indonesian |
it | Italian |
ja | Japanese |
ko | Korean |
ms | Malay |
pt | Portuguese |
ru | Russian |
th | Thai |
vi | Vietnamese |
zh-CN | Chinese-Simplified |
zh-TW | Chinese-Traditional |
Each language code is defined in the toast.GamebaseDisplayLanguage.DefaultCode
constant.
var toast.GamebaseDisplayLanguage.DefaultCode = {
German: 'de',
English: 'en',
Spanish: 'es',
Finnish: 'fi',
French: 'fr',
Indonesian: 'id',
Italian: 'it',
Japanese: 'ja',
Korean: 'ko',
Portuguese: 'pt',
Russian: 'ru',
Thai: 'th',
Vietnamese: 'vn',
Malay: 'ms',
Chinese_Simplified: 'zh-CN',
Chinese_Traditional: 'zh-TW',
};
Display Language can be set when Gamebase is initialized.
API
var gamebaseConfiguration = {
appId: 'T0asTC1oud', // NHN Cloud Console Project ID
clientVersion: '1.0.0', // NHN Cloud Console Gamebase App Client Version
displayLanguageCode: toast.GamebaseDisplayLanguage.DefaultCode.English,
};
toast.Gamebase.initialize(gamebaseConfiguration, (launchingInfo, error) => { ... });
Example
function initialize() {
var gamebaseConfiguration = {
appId: 'T0asTC1oud',
clientVersion: '1.0.0',
displayLanguageCode: toast.GamebaseDisplayLanguage.DefaultCode.English,
};
toast.Gamebase.initialize(gamebaseConfiguration, function (launchingInfo, error) {
if (error) {
// If initialization fails, you cannot use Gamebase SDK.
// Make sure that settings of appId, clientVersion, and NHN Cloud Console have been correctly set.
console.log('Gamebase initialization failed');
console.log(error);
return;
}
const statusCode = launchingInfo.launching.status.code;
if (isPlayable(statusCode)) { // For the status value, see the Launching Status Code table below.
// Game can be played.
console.log('Playable!');
} else {
// Game cannot be played. (maintenance, service terminated, etc.)
console.log('Not Playable!');
}
});
}
You can change the initial setting of Display Language set in Gamebase initialization.
API
var languageCode = '${ISO-639 LanguageCode}';
toast.Gamebase.setDisplayLanguageCode(languageCode);
Example
function setDisplayLanguageCode() {
var languageCode = toast.GamebaseDisplayLanguage.DefaultCode.English;
toast.Gamebase.setDisplayLanguageCode(languageCode);
}
You can retrieve the current application of Display Language.
API
toast.Gamebase.getDisplayLanguageCode();
Example
function getDisplayLanguageCode() {
const language = toast.Gamebase.getDisplayLanguageCode();
console.log(language);
}
To use another language in addition to default Gamebase languages (en, ko, ja), you have to create and enter a JSON object for other language sets. To enter the language sets in Gamebase, call the following API and enter the following:
API
// When try to initialize Gamebase
var displayLanguageTable = {
en: {
common_ok_button: 'Customized OK Text',
common_cancel_button: 'Customized Cancel Text',
}, ...
};
var gamebaseConfiguration = { ..., displayLanguageTable, ... };
toast.Gamebase.initialize(gamebaseConfiguration, (lanchingInfo, error) => { ... });
// After Gamebase was initialized.
toast.Gamebase.setDisplayLanguageTable(displayLanguageTable) {
By default, the localized string embedded in Gamebase is as follows: Format
{
"en": {
"common_ok_button": "OK",
"common_cancel_button": "Cancel",
...
"launching_service_closed_title": "Service Closed"
},
"ko": {
"common_ok_button": "확인",
"common_cancel_button": "취소",
...
"launching_service_closed_title": "서비스 종료"
},
"ja": {
"common_ok_button": "確認",
"common_cancel_button": "キャンセル",
...
"launching_service_closed_title": "サービス終了"
},
}
To add another language sets, add the value in the format of
"${language code}":{"key":"value"}
as the parameter passed to the higher API.
{
"en": {
"common_ok_button": "OK",
"common_cancel_button": "Cancel",
...
"launching_service_closed_title": "Service Closed"
},
"ko": {
"common_ok_button": "확인",
"common_cancel_button": "취소",
...
"launching_service_closed_title": "서비스 종료"
},
"ja": {
"common_ok_button": "確認",
"common_cancel_button": "キャンセル",
...
"launching_service_closed_title": "サービス終了"
},
"${Language code}": {
"common_ok_button": "...",
...
}
}
If a key is missing in ${language code}":{ } of the JSON format above, the language set for the device or 'en' will be automatically entered.
If Display Language is set via initialization and setDisplayLanguageCode API, the final application may be different from what has been entered.
API
toast.Gamebase..addEventHandler(eventHandler);
toast.Gamebase..removeEventHandler(eventHandler);
toast.Gamebase..removeAllEventHandler();
Example
toast.Gamebase.addEventHandler((message) => {
const category = message.category;
const data = message.data;
switch (category) {
case GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT:
// Kicked out from Gamebase server.(Maintenance, banned or etc..)
// Return to title and initialize Gamebase again.
break;
case GamebaseEventCategory.SERVER_PUSH_TRANSFER_KICKOUT:
// If the user wants to move the guest account to another device,
// if the account transfer is successful,
// the login of the previous device is released,
// so go back to the title and try to log in again.
break;
case GamebaseEventCategory.OBSERVER_LAUNCHING:
checkLaunchingStatus(JSON.parse(message.data));
break;
case GamebaseEventCategory.OBSERVER_NETWORK:
checkNetworkStatus(JSON.parse(message.data));
break;
case GamebaseEventCategory.OBSERVER_HEARTBEAT:
checkHeartbeat(JSON.parse(message.data));
break;
case GamebaseEventCategory.OBSERVER_INTROSPECT:
// Introspect error
var observerData = JSON.parse(message.data);
var errorCode = observerData.code;
var errorMessage = observerData.message;
break;
}
});
Example
toast.Gamebase.addEventHandler((message) => {
const category = message.category;
const data = message.data;
switch (category) {
case GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT:
// Kicked out from Gamebase server.(Maintenance, banned or etc..)
// Return to title and initialize Gamebase again.
break;
case GamebaseEventCategory.SERVER_PUSH_TRANSFER_KICKOUT:
// If the user wants to move the guest account to another device,
// if the account transfer is successful,
// the login of the previous device is released,
// so go back to the title and try to log in again.
break;
default:
break;
}
});
Example
toast.Gamebase.addEventHandler((message) => {
const category = message.category;
const data = message.data;
switch (category) {
case GamebaseEventCategory.OBSERVER_LAUNCHING:
checkLaunchingStatus(JSON.parse(message.data));
break;
case GamebaseEventCategory.OBSERVER_NETWORK:
checkNetworkStatus(JSON.parse(message.data));
break;
case GamebaseEventCategory.OBSERVER_HEARTBEAT:
checkHeartbeat(JSON.parse(message.data));
break;
case GamebaseEventCategory.OBSERVER_INTROSPECT:
// Introspect error
var observerData = JSON.parse(message.data);
var errorCode = observerData.code;
var errorMessage = observerData.message;
break;
default:
break;
}
});
function checkLaunchingStatus(data) {
var code = data.code;
var isPlayable = toast.GamebaseLaunching.isPlayable(code);
if (isPlayable) {
// 'The Game is playable'
} else {
// 'The Game is not playable'
}
}
function checkHeartbeat(data) {
var code = data.code;
if (code === toast.GamebaseConstant.INVALID_MEMBER) {
// You should to write the code necessary in game. (End the session.)
} else if (code === toast.GamebaseConstant.BANNED_MEMBER) {
// The ban information can be found by using the GetBanInfo API.
// Show kickout message to user and need kickout in game.
} else {
console.log('Heartbeat code: ' + code);
}
}
function checkNetworkStatus(data) {
var code = data.code;
if (code === toast.GamebaseNetworkType.TYPE_NOT) {
// Network disconnected
} else {
// Network connected
}
}
The game index can be transferred to the Gamebase server.
[Caution]
All APIs supported by the Gamebase Analytics can be called after login.
[TIP]
If payment was made by calling the Gamebase.Purchase.RequestPurchase API, the index is transmitted to the server automatically when the payment is completed.
Please see the following guide for how to use Analytics console.
The game user level information can be transmitted as an index after logging in.
[Caution]
If the SetGameUserData API is not called after login to the game, the level information may be missed from other indexes.
Parameters required for calling the API are as follows:
GameUserData
Name | Mandatory (M) / Optional (O) | type | Desc |
---|---|---|---|
userLevel | M | number | This field represents game user's level. |
channelId | O | string | This field represents channel. |
characterId | O | string | This field represents character name. |
classId | O | string | This field represents class. |
API
var gameUserData = {
userLevel: ${User Level},
channelId: ${Channel Id},
characterId: ${Character Id},
classId: ${ClassId Id},
}
toast.Gamebase.Analytics.setGameUserData(gameUserData);
Example
function setGameUserData(userLevel, channelId, characterId, classId) {
var gameUserData = {
userLevel: userLevel,
channelId: channelId,
characterId: characterId,
classId: classId
}
toast.Gamebase.Analytics.setGameUserData(gameUserData);
}
The game user level information can be transmitted as an index after leveling up.
Parameters required for calling the API are as follows:
LevelUpData
Name | Mandatory (M) / Optional (O) | type | Desc |
---|---|---|---|
userLevel | M | number | This field represents game user's level. |
levelUpTime | O | number | Enter in Epoch time.The unit is milliseconds. |
channelId | O | string | This field represents channel. |
characterId | O | string | This field represents class. |
API
var levelUpData = {
userLevel: ${User Level},
levelUpTime: ${LevelUp Time},
channelId: ${Channel Id},
characterId: ${Character Id},
}
toast.Gamebase.Analytics.traceLevelUp(levelUpData);
Example
function traceLevelUp(userLevel, levelUpTime, channelId, characterId)
{
var levelUpData = {
userLevel: userLevel,
levelUpTime: levelUpTime,
channelId: channelId,
characterId: characterId,
}
toast.Gamebase.Analytics.traceLevelUp(levelUpData);
}