Convert string to blank table reference?

Hello! I am trying to convert a string into a blank table reference, if that’s what it is called. Basically, within a for loop I have, I am converting a set of data into a table. However, whenever I try to register this in a table, it comes up with ["string_here"] instead of string_here when printed. Is there any resolution for this?

What is happening:

local demo_table = {
	["key_here"] = some_value;
}

What I want to happen:

local demo_table = {
	key_here = some_value;
}

Any help is appreciated, as I’m trying to fix this issue soon!

Hi!

What is your use case? - you might be approaching this wrong. :slight_smile:

1 Like

It’s just the way it’s pretty-printed.

The word you’re looking for is “key”, also—you want to use strings as keys in a table.

You’re doing it successfully, there is no problem here. The two pieces of code you posted are exactly equivalent.

It’s like how you can write workspace.Part, but workspace["Part"] does the same thing.

3 Likes

My casing is that I am using setfenv on a function, but the table supplied is script-generated, as just supplying all the tables at once would be less optimized than using setfenv, and setfenv will help with organizing the script.

That’s a lot more involved than your original question!

Could you edit your original post to include details about what exactly you’re trying to do, with for example setfenv?