-
What do you want to achieve?
I am making my own pet system and was wondering if there was a way I can set something like a stringvalue’s name to the name of a table, or set the name of a table to a string value’s name? When saving pet data I wanna create a new table titled the pet’s name, and when loading pet data I wanna create a new pet based on the table’s name. -
What is the issue?
I don’t know if this is something that I can even accomplish. I would like to know or learn a better way to save and load pet data. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I haven’t been able to test anything as I don’t think this would be possible, and I am making this post for confirmation on whether it can be done or not.
Tables don’t have names, so I’m not sure what you mean. What you can do however is have a global table and have mini tables within it where you can pass in the string value’s name as the unique identifier which would be its index.
local GlobalTable = {}
GlobalTable[StringValue.Name] = {}
On Loading Data: Might be convenient to use a function
local function NewPet(Pet)
-- do whatever
end
if GlobalTable[StringValue.Name] then
NewPet(StringValue.Name)
end
I’m not sure if that answers you question, but just ask if you need some more clarification
Hey, this is exactly what I was looking for as I don’t think my method of doing it would’ve been efficient. Also, what I meant by my question is that when you make a table, for instance: local myTable = {}, could you create an object and set its name to the table’s name? If that’s possible would there be any way I could create a table under the name of an object, but not by doing local part.Name = {} as this of course returns an error. Hope that clears up the question, I’ll mark you as solution after any potential response to the question I asked in this reply
Like I mentioned before, tables don’t have names. If you wish to do this, you can just have a key represent the name in your table.
local myTable = {}
myTable.Name = ... -- set the key to whatever
SomeObject.Name = myTable.Name
Like I said just do this, myTable[SomeObject.Name] = {}
Although your question is quite ambiguous, not too sure what you mean by ‘creating a table under the name of the object’, I assume you mean you want to have a key being the objects name, and then the value being the table?
Ok, thank you. I didn’t realize you could do this with tables and I am happy that I learned this! Thanks for your time and help, and have a great rest of your day.