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 » Scripters
Home Search
 

Re: ()

Previous Thread :: Next Thread 
SummerEquinox is not online. SummerEquinox
Joined: 25 Jun 2013
Total Posts: 2088
25 Mar 2015 02:44 PM
What is the "()" for at the end of a function such as
function onClick() <<<< that
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
25 Mar 2015 02:45 PM
inside those brackets is where you would put parameters
Report Abuse
blooo127127 is not online. blooo127127
Joined: 22 Jul 2010
Total Posts: 403
25 Mar 2015 02:48 PM
function TestFunction(Param1,Param2,Param3,Param4)
print(Param1.." "..Param2.." "..Param3.." "..Param4.."!")
end

TestFunction("Luna","is","best","pony")
TestFunction("This","is","a","test")
TestFunction("One","Two","Three",nil)
Report Abuse
SummerEquinox is not online. SummerEquinox
Joined: 25 Jun 2013
Total Posts: 2088
25 Mar 2015 02:50 PM
So I could
onClick(B1,B2)

so long as they are already set as locals?
Report Abuse
blooo127127 is not online. blooo127127
Joined: 22 Jul 2010
Total Posts: 403
25 Mar 2015 02:54 PM
What?

If B1 and B2 haven't been declared anywhere else to cause variable name problems, you should be fine. Any parameter called is automatically made local inside the function and is available to anything inside that function.
Report Abuse
blooo127127 is not online. blooo127127
Joined: 22 Jul 2010
Total Posts: 403
25 Mar 2015 02:56 PM
Some events automatically provide parameters.

game.Players.PlayerAdded:connect(function(player) end) <- Provides player

game.Workspace.ChildAdded:connect(function(object) end) <- Provides whatever just went inside workspace

script.Parent.ClickDetector.MouseClick:connect(function(player) end) <- Provides the player who clicked

Parameters can be called anything, btw.
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
25 Mar 2015 03:22 PM
Other than function declaring the () is also necessary to call a function

If you were to script something like:

function foo()
return 1337
end

You have made the function name foo that just returns 1337. You could do two things with the function foo

var = foo()

and

var = foo

The first one will execute foo without any parameters. And since foo return 1337 var will be set to 1337.

The other one will just set var to foo. So won't be run in this case. var is now a reference to the function foo. you could even call var now like any ordinary function. Like this

var()

The first usage is more common. You don't really need a second variable for a function most of the times.

(And if you where to really mess around you could even do some thing like this:
print = "This is not a function anymore"
)
Report Abuse
Sinblade is not online. Sinblade
Joined: 14 Aug 2010
Total Posts: 2782
25 Mar 2015 03:26 PM
function add (var1, var2)
print(var1 + var2)
)
add(1,5)

Inside we are declaring 2 variables that we can declare when we call the function.
then we are adding and printing the two variables that we defined.
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
25 Mar 2015 03:30 PM
"function add (var1, var2)
print(var1 + var2)
)
add(1,5)"

Looks like someone has been programming in a different language lol. ;)

You need an end where that second closed parenthesis is, for anyone reading these posts.
Report Abuse
Sinblade is not online. Sinblade
Joined: 14 Aug 2010
Total Posts: 2782
25 Mar 2015 03:32 PM
oh man, been trying to learn java


hi
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
25 Mar 2015 03:38 PM
Java is my second favorite language. Lua is my first because of its capabilities for OOP with operator overriding.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
25 Mar 2015 03:43 PM
1.) Why do java developers wear glasses? (Because they can't see sharp)

2.)C Sharp is better

3.) The brackets are parameter; these are the arguments that the function takes. They are like variables specific to the function and are only obtained once the event has been triggered.
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
25 Mar 2015 03:45 PM
Java's new updates have improved my opinion of Java significantly otherwise I'd agree with your second statement. I also love the first one. xD

Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
25 Mar 2015 03:50 PM
One of the things i dislike about lua over c sharp(and java) is that you cannot specifiy the return type of a function. For instance

public void -- Returns nothing
public string --String
public int -- Int
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
25 Mar 2015 03:51 PM
Inside the () is where you put the function parameters. Parameters are input given to the function whenever it is called. The input is then stored in the variables that you provide in the (). Arguments are the actual values of the parameters.

function foo(var1)

end

foo(1)

In the function "foo" above, var1 is the parameter of the function. 1 is the argument, because it is the number passed in when the function is called.
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
25 Mar 2015 03:54 PM
@yobo89
You don't specify the return value in Lua because Lua is meant to be easy to learn, quick, and dynamic. Although it is more efficient to specify the type of return value so that the proper amount of memory can be allocated, it is less flexible, and more difficult to learn.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
25 Mar 2015 03:56 PM
Fair enough..
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
25 Mar 2015 03:58 PM
Languages like that are called "strongly-typed". They are much more fun to use, IMO. I love strongly-typed languages. Then again, the only one I know is C#.
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
25 Mar 2015 06:10 PM
C or C++ is still best :)

Got to love control.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
25 Mar 2015 06:12 PM
"C or C++"
"Got to love control."

Then use assembly.
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
25 Mar 2015 06:13 PM
That isn't a programming language :P
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
25 Mar 2015 06:14 PM
"An assembly language is a low-level programming language for a computer"
"programming language"

Yes, it is by all means a programming language.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Mar 2015 06:16 PM
Java is eww, they have a specific instruction to push constants... I mean really a different instruction to push a 1 or a 2 or a 3...
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
25 Mar 2015 06:18 PM
Write machine code.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
25 Mar 2015 06:20 PM
Make a chip to meet your needs, instead of using a processor.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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