Help with a specific method of function.

Hello facepunch, I’ve been very motivated lately to lean more in depth about gLua and how it genreally works and I came across an opensource upon GitHub. Throughout the code it was your normal things you see, tables, ints, vars but then I stumbled across something what looked like this, I’m not entirely sure why they’re used but it was made something like this…

[LUA]
somethinghere = {
food = food
id = id
steam = steam
inventory = inventory
}

[/LUA]

Could someone please explain why this method is used or if i’ve written it wrong if you could demonstrate to me why and when you’d use it.
Thanks for your help. cx

its setting the table variables with previously gathered variables, usualy after loading in the SQL Data about a player, as example here, it loads the ID, the inventory, the food and the steam(idk what exactly) from the database, and sets it inside the table to be accessed later.

Ah, I see, so it’s mainly for reading data and then reassigning it back to lua?

It’s creating a table, and assigning variables to indexes in it.

I.e. with your current code it’s

  1. Creating a global table named somethinghere
  2. Creating an index called food and assigning it to the value of whatever food is in the current scope.
  3. Repeat 2 with the rest of the variable names

E.g.



local food = randomvalue
local id = randomvalue
local steam = randomvalue
local inventory = randomvalue

-- Later on in code

somethinghere = {
  food = food,
  id = id,
  steam = steam,
  inventory = inventory,
}


To know exactly what values the table holds, you need to know the values of food, id, steam, and inventory are the top portion of the code.