I've been trying to change the name of a variable/function for awhile now.
I really have no Idea. Can someone help? Is it even possible, pls help,pls
change variable/function name?
Started by PixelFox, Jul 18 2015 10:53 PM
11 replies to this topic
#1
Posted 18 July 2015 - 10:53 PM
#2
Posted 18 July 2015 - 11:01 PM
This isn't really possible, nor a thing you should do. What do you need to do this for, exactly? There is likely a better solution than to change variable names.
#3
Posted 18 July 2015 - 11:10 PM
What I want to do is:
*Name controlled by variable* = func()
so if i == "LOL" then
LOL = func()
*Name controlled by variable* = func()
so if i == "LOL" then
LOL = func()
Edited by Lightning, 18 July 2015 - 11:11 PM.
#4
Posted 18 July 2015 - 11:14 PM
But why? What is your end goal?
#5
Posted 18 July 2015 - 11:16 PM
Ugh, nevermind. If someone tells me how. I'd be happy to use it. But until now. Nevermind.
#6
Posted 18 July 2015 - 11:20 PM
You could use a table, but as flaghacker said, we'd need more details to provide an ideal solution.
For example:
For example:
local i = "myFunction"
local tbl = {} --# I suggest you choose a more appropriate name for this variable...
tbl[i] = function()
--# ...
end
tbl.myFunction() --# Now you can do this.
#7
Posted 19 July 2015 - 12:08 AM
It looks like he wants to change the name of a variable containing what func() returns. Not that the variable is a function.
You could just create a second variable, make it point to the old, and then clear the old one.
You could just create a second variable, make it point to the old, and then clear the old one.
local var = func() --do some stuff here local otherVar = var var = nil
Edited by H4X0RZ, 19 July 2015 - 12:09 AM.
#8
Posted 19 July 2015 - 01:17 AM
More importantly, function names aren't important. I could name a function 'killallthecomputercraftusers' and it would still work the same. Function names aren't shown to the user, so who cares what it's called? And whatever system you DO use will clutter up the environment with function pointers that you will NEVER call. Edit: Unless you take H4X0RZ's suggestion.
Edited by Dragon53535, 19 July 2015 - 01:18 AM.
#9
Posted 19 July 2015 - 09:56 AM
Renaming variables is plain pointless, as stated by other users. If you tell us what is your end goal we will help you solve your problem in a better way.
#10
Posted 19 July 2015 - 05:00 PM
Thanks, HAX0Rz! Now I can do it
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












