Make a table/variable name out of the table/variable content?

So here are some examples to show what I am talking about



local playerid = "lol"
LocalPlayer().players.playerid = "pineapple"

print(LocalPlayer().players.lol)


Expected output: pineapple



button.id = "player"
function button:DoClick()
    LocalPlayer().players.button.id = "lelz"
end

print(LocalPlayer().players.player)


Expected output: lelz



button.xd = 78
function button:DoClick()
    LocalPlayer().players.button.xd = "meme"
end

print(LocalPlayer().players.78)


Expected output: meme

Player.players is nil and so is Player.players.button. They need to be tables.

You can’t use variables like that. All three will be nil because they are undefined on the player table. You would have to do:


LocalPlayer().players.lol = "pineapple"

For the first example if you wanted the expected output.

ah sorry they are defined but I forgot to put them in the examples.

And here is the problem, I want to make a history for each player that the player has chatted with



LocalPlayer().tablet_text_my.Mike = {}
LocalPlayer().tablet_text_my.Bot01 = {}
LocalPlayer().tablet_text_my.Bot02 = {}


LocalPlayer is not a global player entity: it is a single player – specifically, the clientside one. I would do this serverside:


local tChatLogs = {}

hook.Add("OnEntityCreated", "ChatLogs", function(pEntity)
	if (pEntity:IsPlayer()) then
		tChatLogs[pEntity] = {}
	end
end)

hook.Add("EntityRemoved", "ChatLogs", function(pEntity)
	if (pEntity:IsPlayer()) then
		tChatLogs[pEntity] = nil
	end
end)

hook.Add("PlayerSay", "ChatLogs", function(pPlayer, sText)
	table.insert(tChatLogs[pEntity], sText)
end)

Note that this does have a few restrictions:

  • It is not run after all PlayerSay hooks, so some commands could be logged. You could get around this with a clientside OnPlayerChat/ChatText hook, but the logs would differ between each player
  • It is not networked, and must be done so manually. The alternative provided above applies here, as well
  • It is not persistent, and will clear between maps and crashes. Alternative is to use a text file to store the strings, or a similar structure.

The best implementation will depend on your specific case.

But that’s clientside derma with DTextEntry

What? There is no derma or DTextEntry.

They were examples on how I think it’ll work or to show what I mean

Is this what you mean?



local playerid = "lol"
LocalPlayer().players[playerid] = "pineapple"

print(LocalPlayer().players.lol)


output: pineapple



button.id = "player"
function button:DoClick()
    LocalPlayer().players[self.id] = "lelz"
end

print(LocalPlayer().players.player)


output: lelz



button.xd = 78
function button:DoClick()
    LocalPlayer().players.button[xd] = "meme"
end

print(LocalPlayer().players[78])


output: meme

You’re my savior thank you, I mean… it isn’t what I asked for but it’ll still work.