Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Information

The reflection helper is a powerful part of Lua coding, it helps to access values for GetField, GetValue, IsContainer and ToContainer.

Component vs SingletonComponent

Component

Is a storage per local entity, each entity can have their own instance of some component.
Lua:

EntityService:GetComponent(ENTITY, "COMPONENT")

SingletonComponent

Is for global storage and is not tied to any entity, no matter in which place you call it you will get the same instance of the data.
Lua:

EntityService:GetSingletonComponent("COMPONENT")

Using the reflection helper

At the beginning of your lua file should be the require for the reflection element:

require("lua/utils/reflection.lua")

In your code, use the reflection helper in combination with components to access component values:

local refl_MechComponent = reflection_helper( EntityService:GetComponent(self.entity, "MechComponent"))
LogService:Log( tostring(refl_MechComponent)  )

If you need to go one “layer” deeper into the information, you can use Dot Notation and just append what you need, for example:

refl_MechComponent.zoom 
refl_MechComponent.velocity 
refl_MechComponent.pickup_radius

Use the game reflection to get an overview of available components and their properties