Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I use dynamic variable names?

So, I have two tables "trks" and "fabs". "trk" and "fab" are two possible values of a variable I have. If the variable is "trk" I want it to pull from the table "trks", and if it's "fab" I want it to pull from the table "fabs". I tried this, but it was invalid syntax, so I decided to ask y'all.

if hairColChosen > #[hairs[hairChosen] .. "s"] then
	--do the stuff
end

1 answer

✓ Accepted answer

You don't want to do that -- it would get really confusing (what if it was "game"? what if it was a parameter to your function? etc. it get's messy, and slow)

Instead, you should be pulling from a table.

local choices = {
	trks = "hello",
	fabs = "goodbye",
}


local choice = "trks"
print(choices[choice]) --> hello

3 comments

0

could i have "hello" and "goodbye" set to another table?

0

I wish there was a super syntax, that would be pretty useful

0

Yes, of course you can put whatever you want inside of the choices table. This is just a simple example.

This discussion is preserved as it was. New answers, comments, and votes are closed.