This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
PixelFox's profile picture

change variable/function name?

Started by PixelFox, 18 July 2015 - 09:53 PM
PixelFox #1
Posted 18 July 2015 - 11:53 PM
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
Lignum #2
Posted 19 July 2015 - 12:01 AM
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.
PixelFox #3
Posted 19 July 2015 - 12:10 AM
What I want to do is:


*Name controlled by variable* = func()

so if i == "LOL" then

LOL = func()
Edited on 18 July 2015 - 10:11 PM
flaghacker #4
Posted 19 July 2015 - 12:14 AM
But why? What is your end goal?
PixelFox #5
Posted 19 July 2015 - 12:16 AM
Ugh, nevermind. If someone tells me how. I'd be happy to use it. But until now. Nevermind.
Lignum #6
Posted 19 July 2015 - 12:20 AM
You could use a table, but as flaghacker said, we'd need more details to provide an ideal solution.
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.
H4X0RZ #7
Posted 19 July 2015 - 01: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.

 
local var = func() 
--do some stuff here 
local otherVar = var
var = nil 
Edited on 18 July 2015 - 11:09 PM
Dragon53535 #8
Posted 19 July 2015 - 02: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 on 19 July 2015 - 12:18 AM
MKlegoman357 #9
Posted 19 July 2015 - 10: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.
PixelFox #10
Posted 19 July 2015 - 06:00 PM
Thanks, HAX0Rz! Now I can do it :D/>
cmdpwnd #11
Posted 19 July 2015 - 08:28 PM
Thanks, HAX0Rz! Now I can do it :D/>/>

So what are you using it for? :)/>
H4X0RZ #12
Posted 19 July 2015 - 10:39 PM
Thanks, HAX0Rz! Now I can do it :D/>/>

So what are you using it for? :)/>

I would like to know that too :D/>