Greets everyone,
I'm encountering a problem that I'm sure has a simple solutions, but I'm just missing it.
I have a table used for another purpose, but would like to use the information in that table to construct a different table.
This original table looks like this:
What I want to do is make a function that uses this table to create a new table where the keys are the races and the values are the names of people that belong to that race.
Thus one of the key value pairings in this new table would be:
dwarf = "jim, john"
etc.
I tried doing this:
Of course, the problem with this is that instead of adding the name to the value of the race key, it's overwriting the value.
Any ideas on how to get each name added to the respective race key?
Please let me know if I need to clarify anything or further information is required.
I'm encountering a problem that I'm sure has a simple solutions, but I'm just missing it.
I have a table used for another purpose, but would like to use the information in that table to construct a different table.
This original table looks like this:
characters = {
{name = "jim" ,race = "dwarf" ,class = "priest"}
{name = "john" ,race = "dwarf" ,class = "warrior"}
{name = "ben" ,race = "human" ,class = "priest}
{name = "lynn" ,race = "elf" ,class = "warrior"}
{name = "terry" ,race = "elf" ,class = "warrior"}
}What I want to do is make a function that uses this table to create a new table where the keys are the races and the values are the names of people that belong to that race.
Thus one of the key value pairings in this new table would be:
dwarf = "jim, john"
etc.
I tried doing this:
for _, v in ipairs(characters) do
race_index [v.race] = v.name
endOf course, the problem with this is that instead of adding the name to the value of the race key, it's overwriting the value.
Any ideas on how to get each name added to the respective race key?
Please let me know if I need to clarify anything or further information is required.