value definition function||doc135544

September 20, 2022

Format

 Entity.addValueFunc(key, func)
  • The class to which the function belongs:Entity

Description

The callback function when the value defined by the registered value changes.


Precautions

  • Often used with addValueDef
  • Usually, the callback function defined by the value will register different callback functions on the server side and the client side. The server side is used for the effect of property value change, and the client side is used for the change on the interface when the property changes.
  • Note: The data store must be turned on to sync data to the database

Parameters

Variable name type Description
key string key
func function Callback


Code Samples

in publicglobal script, add a value definition, when the value changes,broadcast tipsnewly changed value

Entity.addValueDef("score", 2, true, true, true)         --Note that "Entity" here can only be defined with this name
Entity.addValueFunc("score", function(entity, value)    
    World.CurWorld.SystemNotice(1, value, 40)            --Broadcast
end)