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: What's the difference?

Previous Thread :: Next Thread 
hello3396 is not online. 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 is not online. hello3396
Joined: 18 Dec 2008
Total Posts: 1631
07 Dec 2013 02:14 PM
Bump
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
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
KiwiMeister is not online. KiwiMeister
Joined: 18 Feb 2010
Total Posts: 1464
07 Dec 2013 02:28 PM
What's the Scope?
Report Abuse
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
07 Dec 2013 02:32 PM
A nice article on Scope:

http://wiki.roblox.com/index.php/Scope
Report Abuse
hello3396 is not online. 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 is not online. 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 is not online. hello3396
Joined: 18 Dec 2008
Total Posts: 1631
07 Dec 2013 02:40 PM
function x()
What's the () for?
Report Abuse
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
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
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
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 is not online. 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
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
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 is not online. hello3396
Joined: 18 Dec 2008
Total Posts: 1631
07 Dec 2013 02:46 PM
? What's "passing arguments"?
Report Abuse
vlekje513 is not online. 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
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
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 is not online. 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 is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
07 Dec 2013 02:57 PM
Because that's the RBX.Lua syntax!
Report Abuse
hello3396 is not online. 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 is not online. 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
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
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 is not online. 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 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
07 Dec 2013 03:25 PM
http://wiki.roblox.com/index.php/Function
Report Abuse
hello3396 is not online. hello3396
Joined: 18 Dec 2008
Total Posts: 1631
07 Dec 2013 03:27 PM
Thx Guys I finally get it :))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
07 Dec 2013 03:31 PM
Hooray!
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
07 Dec 2013 03:33 PM
Yay, what made you get it?
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