[Base Class](../groups/Extension.Base Class.md) / DataCenterC
DataCenterC Class
The client data center stores the data of the current Player
Usage example: create a script named DataCenterCExample, place it in the object bar, open the script, modify the original content as follows, save and run the game, and you will see the Player data is ready and the Player level is 0 in the client log
@Component
export default class DataCenterCExample extends Script {
protected onStart(): void {
this.traceLevel();
}
//Wait for Player data to be ready and output the level of Player data
public async traceLevel(): Promise<void> {
if (SystemUtil.isClient()) {
//Wait for Player data to be ready
await DataCenterC.ready();
Console.log ("Player data ready");
let playerData = DataCenterC.getData(PlayerModuleData);
Console. log ("Player level:", playerData. getlevel());
}
}
}
class PlayerModuleData extends Subdata {
@Decorator.persistence()
private level: number = 0;
public getlevel(): number {
return this.level;
}
}
@Component
export default class DataCenterCExample extends Script {
protected onStart(): void {
this.traceLevel();
}
//Wait for Player data to be ready and output the level of Player data
public async traceLevel(): Promise<void> {
if (SystemUtil.isClient()) {
//Wait for Player data to be ready
await DataCenterC.ready();
Console.log ("Player data ready");
let playerData = DataCenterC.getData(PlayerModuleData);
Console. log ("Player level:", playerData. getlevel());
}
}
}
class PlayerModuleData extends Subdata {
@Decorator.persistence()
private level: number = 0;
public getlevel(): number {
return this.level;
}
}
Table of contents
Properties
onInitResult: Action2 <number , string > |
---|
Delegate of data initialization result, the parameters are: result code (0- success, 1- failure to load data form 2- failure to load sub data), error content |
Methods
getData<T : extends Subdata <T >>(SubdataType : TypeName <T : extends Subdata <T >>): T : extends Subdata <T > other |
---|
Obtain data for the current player |
ready(): Promise <void > other |
Determine if the data is ready |
Properties
onInitResult
▪ Static
Readonly
onInitResult: Action2
<number
, string
>
Delegate of data initialization result, the parameters are: result code (0- success, 1- failure to load data form 2- failure to load sub data), error content
Methods
getData
• Static
getData<T
>(SubdataType
): T
other
Obtain data for the current player
Parameters
SubdataType TypeName <T > | data type |
---|
Returns
T | data object |
---|
Usage example: create a script named DataCenterCExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and you will see the information of Player whose level is 0 in the client log
@Component
export default class DataCenterCExample extends Script {
protected onStart(): void {
this.traceLevel();
}
//Wait for Player data to be ready and output the level of Player data
public async traceLevel(): Promise<void> {
if (SystemUtil.isClient()) {
//Wait for Player data to be ready
await DataCenterC.ready();
let playerData = DataCenterC.getData(PlayerModuleData);
Console. log ("Player level:", playerData. getlevel());
}
}
}
class PlayerModuleData extends Subdata {
@Decorator.persistence()
private level: number = 0;
public getlevel(): number {
return this.level;
}
}
@Component
export default class DataCenterCExample extends Script {
protected onStart(): void {
this.traceLevel();
}
//Wait for Player data to be ready and output the level of Player data
public async traceLevel(): Promise<void> {
if (SystemUtil.isClient()) {
//Wait for Player data to be ready
await DataCenterC.ready();
let playerData = DataCenterC.getData(PlayerModuleData);
Console. log ("Player level:", playerData. getlevel());
}
}
}
class PlayerModuleData extends Subdata {
@Decorator.persistence()
private level: number = 0;
public getlevel(): number {
return this.level;
}
}
Type parameters
T | extends Subdata <T > |
---|
ready
• Static
ready(): Promise
<void
> other
Determine if the data is ready
Returns
Promise <void > | True - ready fall - not ready |
---|