generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Creating a variable for functions?

Previous Thread :: Next Thread 
Jinxy is not online. Jinxy
Joined: 04 Aug 2007
Total Posts: 18317
10 Jul 2011 12:47 PM
So I'm here reading Dingdong's guide to scripting, and so I was curious if I can make a function, and then name it as a variable. I COULD do it right now, but I think it better to ask before trying, just in case the game crashes...
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
10 Jul 2011 12:48 PM
Like,

func = function a(hit)

?
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
10 Jul 2011 12:48 PM
Well you can return a function, giving it a value.. or you could use an anonymous function, if that's what you mean.
Report Abuse
Jinxy is not online. Jinxy
Joined: 04 Aug 2007
Total Posts: 18317
10 Jul 2011 12:51 PM
@chicken, yes something of that nature.
@Flurite, that's what I mean.
Report Abuse
Corecii is not online. Corecii
Joined: 06 Aug 2010
Total Posts: 687
10 Jul 2011 12:51 PM
FunctionName = function(Arg1,Arg2,Etc)
print(Arg1,Arg2,Etc)
end

It can also be done:

function FunctionName(Arg1,Arg2,Etc)
end

You can ad 'local' in front of either one of those to make it local.
Report Abuse
Jinxy is not online. Jinxy
Joined: 04 Aug 2007
Total Posts: 18317
10 Jul 2011 12:53 PM
What does making it local do?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
10 Jul 2011 01:31 PM
Limits the use of the variable to the current scope. Same as just defining a local variable (that's what is happening anyway).
Report Abuse
DrAgonmoray is not online. DrAgonmoray
Joined: 29 Jul 2008
Total Posts: 17428
10 Jul 2011 01:33 PM
Making it local adds it to the local scope, which is faster in most cases.
You're a beginner, so I don't think you should worry about scopes too much right now.

--This is a scope
local a = 1
function bob()
--Inside a function is a new scope
local a = 2
--This a is 2 inside this scope
print("Bob scope: " ..a)
end
bob()
--But it is still 1 inside this scope
print("Regular scope: "..a)
Report Abuse
Jinxy is not online. Jinxy
Joined: 04 Aug 2007
Total Posts: 18317
10 Jul 2011 01:40 PM
Yeah, I won't worry too much about scopes now then... I just heard the local command so often, I wanted to know what it did.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image