set object data||doc135425

September 20, 2022

Format

 Object:setData(key, val) 
  • The class to which the function belongs:Object

Description

To set the specified object data, you can access the data you need on the object through the setData and data functions.


Precautions

  • The data in the two ends are not connected. For example, if the data is set in the client, it cannot be obtained in the server.

Parameters

Variable name type Description
key string data key
val variant data


Code Samples

On the server side of the entity objectmount script, add a registered player when logging into the gameCallback, set the score of the entity to 1

Trigger.addHandler(this:cfg(), "ENTITY_ENTER", function(context)
    local player = context.obj1
    player:setData('score',1)
end)