How to call a class/table value by its name

I’ve been struggling with this problem for a while and couldn’t find answers anywhere as I don’t know the correct terminology on this issue:

 

I have a table named “items”, which among other properties has the following property:

 

items.quantity = 4

 

Now I want to read that values with a function that takes the class property (quantity) as a string:

 

getItemProperty({property = “quantity”})

 

and the function should search the class for a property named “quantity” and return it. I can’t figure out the correct syntax. How is this done? items.quantity gives the output of 4 so the table is fine.

 

I’ve already tried the following syntax with no success

 

function getItemProperty(parameters)

{

local value = items.‘parameters.property’

return value

}

In lua
items.quantity and items[“quantity”] is the same in functional meaning :slight_smile:

So you even do not have to write function :slight_smile:

I actually do need the function as it does other actions among the property picking, but the main problem is now solved. Thanks for your help, it makes a lot of sense now.

In lua
items.quantity and items[“quantity”] is the same in functional meaning :slight_smile:

So you even do not have to write function :slight_smile:

I actually do need the function as it does other actions among the property picking, but the main problem is now solved. Thanks for your help, it makes a lot of sense now.