KBEngine Module
The KBEngine module provides access to parts of Entity at the logic script layer, as well as data of the current space, etc.
Member Functions
def getCustomCfg( key, default=None ):
def login( username, password ):
def createAccount( username, password ):
def reloginBaseapp():
def player( ):
def resetPassword(username):
def bindAccountEmail( emailaddress ):
def newPassword( oldpassword, newpassword ):
def findEntity( entityID ):
def getSpaceData( key ):
Properties
entity_uuid uint64
entity_id int32
spaceID int32
Member Function Documentation
def getCustomCfg( key, default=None ):
Available since: 2.8.2
Description:
Reads a custom configuration item from the <customCfg> section of the server configuration file. This API is read-only; scripts cannot modify configuration values through it.
Each item is described by a unified <param> node: name is the key used by scripts, type controls the Python object type returned to scripts, and the node text is the configuration value. desc is only documentation in the configuration file and is not loaded into runtime memory.
Supported type values: bool, int, float, string, dict, and list.
When the item exists, the return type is determined only by the XML type, not by the default argument. When the item does not exist, this function returns default if it is provided, otherwise it returns None.
Configuration example:
<customCfg>
<param name="battle.maxPlayers" type="int" desc="max players per battle">100</param>
<param name="battle.enableRank" type="bool" desc="enable battle rank">true</param>
<param name="battle.speedScale" type="float" desc="battle speed scale">1.0</param>
<param name="battle.welcome" type="string" desc="welcome text">hello</param>
<param name="battle.dropRates" type="dict" desc="drop rate config">{"gold": 1.2, "item": 0.05}</param>
<param name="battle.spawnPoints" type="list" desc="spawn point ids">[1, 2, 3]</param>
</customCfg>Example:
import KBEngine
maxPlayers = KBEngine.getCustomCfg("battle.maxPlayers", 100)
enableRank = KBEngine.getCustomCfg("battle.enableRank", False)
dropRates = KBEngine.getCustomCfg("battle.dropRates", {})
spawnPoints = KBEngine.getCustomCfg("battle.spawnPoints", [])
# Returns None when the key does not exist and no default value is provided.
missingValue = KBEngine.getCustomCfg("battle.null")Parameters:
key: string, the custom configuration item name, corresponding to <param name="...">.
default: optional object returned when the configuration item does not exist. If omitted, None is returned.
Returns:
The Python object converted according to type when the item exists; otherwise default or None.
def login( username, password ):
Description:
Login to the KBEngine server.
Note: If the plugin and UI layer use event interaction mode, do not call this directly in the UI layer. Please trigger a "login" event to the plugin, with username and password as event data.
Parameters:
username: string, username.
password: string, password.
def createAccount( username, password ):
Description:
Request to create a login account on the KBEngine server.
Note: If the plugin and UI layer use event interaction mode, do not call this directly in the UI layer. Please trigger a "createAccount" event to the plugin, with username and password as event data.
Parameters:
username: string, username.
password: string, password.
def reloginBaseapp( ):
Description:
Request to re-login to the KBEngine server (usually used after disconnection to reconnect to the server and continue controlling the server character in a timely manner).
Note: If the plugin and UI layer use event interaction mode, do not call this directly in the UI layer. Please trigger a "reloginBaseapp" event to the plugin, with empty event data.
def player( ):
Description:
Get the entity currently controlled by the client.
Returns:
Entity, returns the controlled entity. If it does not exist (e.g., not connected to the server), returns null.
def resetPassword( username ):
Description:
Request loginapp to reset the account password. The server will send a password reset email to the email address bound to the account (usually used for "forgot password" functionality).
Parameters:
username: string, username.
def bindAccountEmail( emailaddress ):
Description:
Request baseapp to bind the account's email address.
Parameters:
emailaddress: string, email address.
def newPassword( oldpassword, newpassword ):
Description:
Request to set a new password for the account.
Parameters:
oldpassword: string, old password.
newpassword: string, new password.
def findEntity( entityID ):
Description:
Find the instance object of an entity by its ID.
Parameters:
entityID: int32, entity ID.
Returns:
Entity, returns the entity instance if it exists, otherwise returns null.
def getSpaceData( key ):
Description:
Get the space data for the specified key.
Space data is set by the user on the server via setSpaceData.
Parameters:
key: string, a string key.
Returns:
string, the string data for the specified key.
Property Documentation
component
Description:
This is the component currently running in the script environment. (So far) possible values are 'cellapp', 'baseapp', 'client', 'dbmgr', 'bots', and 'editor'.
entities
Description:
entities is a dictionary object containing all entities on the current process.
Type:
entity_uuid
Description:
The uuid of the entity, this ID is bound to the entity for this login session. When using the relogin function, the server will compare with this ID to determine validity.
entity_id
Description:
The ID of the entity currently controlled by the client.
spaceID
Description:
The space ID where the entity currently controlled by the client is located (can also be understood as the corresponding scene, room, or instance).