Creating a variable out of the function's return./ Turning string into variable name.

So I have this simple code for now:



net.Receive("mvsm_update", function()
end)


And I am writing a net.WriteString()
And I want to retrieve it using net.ReadString() and create a variable out of the return so for example:



net.ReadString() = 50
print(ttt_nuclear_power_v3)


and the string inside net.ReadString() is (“ttt_nuclear_power_v3”)
sooooooo any help?

_G[net.ReadString()] = something

[editline]27th July 2017[/editline]

But needles to say, if you need to do this, you’ve made some bad design choices. If you post what you are trying to do, someone might be able to suggest a better solution

I’ve read something and I saw _G are global variables? I might be wrong but aren’t global variables available across all addons?

Global variables are accessible everywhere in the state they are defined.

hm then can I do local _G[net.ReadString()] = something
to make them available only in the net.Receive() function?

If you want those values local to the scope of that function, declare a local table in that function, and store the received values in that table instead of in _G

wait so _G is a table?

Yup.

oooooh

Why aren’t you just doing



local ttt_nuclear_power_v3 = net.ReadString()


or if ttt_nuclear_power_v3 is global then



ttt_nuclear_power_v3 = net.ReadString()


edit:

Misread it, i’m really ignorant

Because he wants the name of the variable to be determined by the net message, not just its value.

doesn’t loadstring do this loadstring(yourvariablenameinstringformat…" = "…net.ReadString())

Aren’t you looking to do something like

[Lua]
GlobalTable[net.ReadString()] = 50
print(GlobalTable.ttt_nuclear_powerv3) //50
print(Global table[“ttt_nuclear_powerv3”]) //50
[/Lua]

Since I guess you want to use that net message as key