set value define value||doc135545

September 20, 2022


 Entity:setValue(key, value, noSync)
  • The class to which the function belongs:Entity


The value defined by the setting value is mostly used for data storage.


  • only when adding a value definitionclientWhen it is true, the value can be modified on the client side, otherwise an error will occur when synchronizing the server side
  • Note: The data store must be turned on to sync data to the database


Variable name type Description
key string key
value variant value
noSync boolean disable sync

Code Samples

in publicglobal script, add the value definition

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

on the server sideglobal script, add a registered player object when it diesCallback, if the value of the definition "score" is greater than 1, it is set to half of the original

Trigger.addHandler(Entity.GetCfg("myplugin/player1"), "ENTITY_DIE", function(context)
 local player = context.obj1 
 local score = player:getValue("score ") --Gets the value of the entity value that defines "score"
 if score >1 then --If the value is greater than 1
 player:setValue("score",score / 2) -- Set the value to half the original
end )