Add value definition||doc135543

September 20, 2022


 Entity.addValueDef(key, init, toSelf, toOther, saveDB, client) 
  • The class to which the function belongs:Entity


Add a value definition, and the entity object automatically synchronizes with the saved attribute value definition.


  • Often used with addValueFunc
  • Usually, the operation of adding value definitions will be executed in the public global script, which can ensure that the attribute values of the server and the client are defined, so as to avoid the situation of undefined values during synchronization
  • Note: The data store must be turned on to sync data to the database


Variable name type Description
key string key
init variant initial value
toSelf boolean Whether to synchronize to your own client
toOther boolean Whether to sync to other user clients
saveDB boolean Whether to save
client boolean Can the client make changes

Code Samples

in publicglobal script, add the value definition

Entity.addValueDef("score", 2, true, true, false, true) -- Note that "Entity" here can only be defined with this name / Note that "Entity" here can only be defined by that name