Jump to content




change variable/function name?


  • You cannot reply to this topic
11 replies to this topic

#1 PixelFox

  • Members
  • 106 posts

Posted 18 July 2015 - 10: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

#2 Lignum

  • Members
  • 558 posts

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 PixelFox

  • Members
  • 106 posts

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()

Edited by Lightning, 18 July 2015 - 11:11 PM.


#4 flaghacker

  • Members
  • 655 posts

Posted 18 July 2015 - 11:14 PM

But why? What is your end goal?

#5 PixelFox

  • Members
  • 106 posts

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 Lignum

  • Members
  • 558 posts

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:
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 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

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.

 
local var = func() 
--do some stuff here 
local otherVar = var
var = nil 

Edited by H4X0RZ, 19 July 2015 - 12:09 AM.


#8 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

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 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

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 PixelFox

  • Members
  • 106 posts

Posted 19 July 2015 - 05:00 PM

Thanks, HAX0Rz! Now I can do it :D

#11 cmdpwnd

  • Members
  • 128 posts
  • LocationHere

Posted 19 July 2015 - 07:28 PM

View PostLightning, on 19 July 2015 - 05:00 PM, said:

Thanks, HAX0Rz! Now I can do it :D/>

So what are you using it for? :)

#12 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 19 July 2015 - 09:39 PM

View Postjacky500, on 19 July 2015 - 07:28 PM, said:

View PostLightning, on 19 July 2015 - 05:00 PM, said:

Thanks, HAX0Rz! Now I can do it :D/>

So what are you using it for? :)

I would like to know that too :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users