get value definition||doc135542

September 20, 2022

Format

 Entity:getValue(key)
  • The class to which the function belongs:Entity

Description

Get the value definition based on the key.


Precautions

  • Be sure to add a value definition before you can get it, otherwise unexpected things will happen
  • Note: The data store must be turned on to sync data to the database

Parameters

Variable name type Description
key string key


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
end )