hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 02:06 PM |
What's the difference between a variable, "local" and "function"? They all seem the same to me -.- |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
| |
|
|
| 07 Dec 2013 02:26 PM |
| They're three different things. "local" declares something to be local to the scope it is in. Variables and functions are exactly what they're called. |
|
|
| Report Abuse |
|
|
| |
|
|
| 07 Dec 2013 02:32 PM |
A nice article on Scope:
http://wiki.roblox.com/index.php/Scope |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 02:32 PM |
| I don't understand local still, what's a scope? What do you mean by when you make "local to the scope it is in"? |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 02:39 PM |
Ok, I think I get it now. Basically "Local ____" works until "end" and the "____" is a scope? That's when you use a new "local" Right? |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 02:40 PM |
function x() What's the () for? |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2013 02:41 PM |
Red = true
function yolo() local ThisVariableWontWorkOutsideTheFunction = true if Red then //This variable works inside the function local ThisVariabelWontWorkOutsideTheIfThenStatement = true end end |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2013 02:42 PM |
So many questions :p
The () is there to tell Lua that it is a function. Sometimes you can put stuff in there too.
function PrintNumber(number) print(number) //prints out what it gets end
PrintNumber(55555)//The number is sent the the function. |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 02:44 PM |
Sorry about the questions, I've been trying to script for a while and don't get it :I
So the string instead the (), what's it's purpose?
|
|
|
| Report Abuse |
|
|
|
| 07 Dec 2013 02:44 PM |
The parentheses are for passing arguments to the function.
function Derp(a,b,c) print(a,b,c) end
Derp("Hooray","for","arguments!")
> Hooray for arguments! |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 02:46 PM |
| ? What's "passing arguments"? |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 07 Dec 2013 02:49 PM |
function FUNCTIONNAME(WHATTOUCHEDIT) print(WHATTOUCHEDIT) if WHATTOUCHEDIT.Parent.Humanoid then WHATTOUCHEDIT.Parent.Humanoid.Health = WHATTOUCHEDIT.Parent.Humanoid.MaxHealth end end
script.Parent.Touched:connect(FUNCTIONNAME) |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2013 02:51 PM |
| It's sort of like math: plug in x, get y. In this case, we're plugging stuff we want into functions. |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 02:56 PM |
| from vlekje513 post, the () is like creating a variable? I still don't understand why you need it? |
|
|
| Report Abuse |
|
|
CrniOrao
|
  |
| Joined: 12 Oct 2008 |
| Total Posts: 2274 |
|
|
| 07 Dec 2013 02:57 PM |
| Because that's the RBX.Lua syntax! |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 03:00 PM |
function FUNCTIONNAME(WHATTOUCHEDIT) print(WHATTOUCHEDIT) if WHATTOUCHEDIT.Parent.Humanoid then WHATTOUCHEDIT.Parent.Humanoid.Health = WHATTOUCHEDIT.Parent.Humanoid.MaxHealth end end
why doesn't he use that instead? -.- ????
function FUNCTIONNAME(WHATTOUCHEDIT) print(FUNCTIONNAME) if FUNCTIONNAME.Parent.Humanoid then FUNCTIONNAME.Parent.Humanoid.Health = FUNCTIONNAME.Parent.Humanoid.MaxHealth end end |
|
|
| Report Abuse |
|
|
CrniOrao
|
  |
| Joined: 12 Oct 2008 |
| Total Posts: 2274 |
|
|
| 07 Dec 2013 03:06 PM |
Because functionname haves nothing to do with the argument.
function NAMEOFIT(ARGUMENT)
and then depending on what you're doing ARGUMENT is defined. For touched ARGUMENT is the part that touched it.
--Touched script.Parent.Touched:connect(NAMEOFIT) --TouchEnded script.Parent.TouchEnded:connect(NAMEOFIT) --ARGUMENT would be the part that touched it has stopped touching it.
AND SO ON! :D |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2013 03:15 PM |
Okay, let's start with basic math.
y = 5x + 2
Surely you know what that is right? It's an equation. Think of a function as plugging in x to get y. If you plug in 2 for x, you will get 12 for y. Now let's talk about functions. Here's a function that will print the sum of the two arguments you pass to it.
function Add(Number1,Number2) print(Number1 + Number2) --Prints the sum of the two numbers you give it end
Let's say I want it to print the sum of 2 and 5.
Add(2,5)
It will then print 7. See how that works? You're basically giving the function cookies to eat or toys to play with. |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 03:23 PM |
| Ok, do you have a very easy example I could look at it |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 07 Dec 2013 03:25 PM |
| http://wiki.roblox.com/index.php/Function |
|
|
| Report Abuse |
|
|
hello3396
|
  |
| Joined: 18 Dec 2008 |
| Total Posts: 1631 |
|
|
| 07 Dec 2013 03:27 PM |
| Thx Guys I finally get it :)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) |
|
|
| Report Abuse |
|
|
| |
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 07 Dec 2013 03:33 PM |
| Yay, what made you get it? |
|
|
| Report Abuse |
|
|