object data||doc135424

September 20, 2022

Format

 Object:data(key) 
  • The class to which the function belongs:Object

Description

To get the specified object data, you can access the data you need on the object through the setData and data functions. When fetching, if the data does not exist, it will automatically return an empty table {} .


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


Value Returned

type Description
variant data


Code Samples

On the server side of the entity objectmount script, when the registered entity diesCallback, get the entity score

Trigger.RegisterHandler(this:cfg(), "ENTITY_DIE", function(context)
    local player = context.obj1
    local score = player:data('score')
    print(score)
end)