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 |
|
|
|
| 10 Jul 2011 12:48 PM |
Like,
func = function a(hit)
? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 04 Aug 2007 |
| Total Posts: 18317 |
|
|
| 10 Jul 2011 12:53 PM |
| What does making it local do? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|