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 point in "()". It's completely empty! Why do we even use them?

Previous Thread :: Next Thread 
ShadowKnight619ALT is not online. ShadowKnight619ALT
Joined: 25 Mar 2011
Total Posts: 102
21 Dec 2011 02:05 PM
I use it because it makes the script work, but I don't understand why.
Let me give an example:

function OnTouched ()

Now, you could have:
function OnTouched(hit)

In the second example, the brackets serve a purpose.
Report Abuse
cart6157 is not online. cart6157
Joined: 28 Feb 2009
Total Posts: 2194
21 Dec 2011 02:10 PM
What? Are you too lazy to writena few parenthesises?
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
21 Dec 2011 02:13 PM
The brackets clarify that you are calling/defining a function.

function a()
print("Cookies")
end

print(a())
print(a)
>Cookies
>function: [Hexadecimal code presumably of the function's memory address]
Report Abuse
ShadowKnight619ALT is not online. ShadowKnight619ALT
Joined: 25 Mar 2011
Total Posts: 102
21 Dec 2011 02:18 PM
So would I not need to put () after an 'if'
For example, which would work:
if OnClicked()

or

if OnClicked
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
21 Dec 2011 02:25 PM
Well, what you just said in the 'if OnClicked()' (Which btw has some errors), you are assuming that the function returns true or false.

i.e.

    function OnClicked()
        return true
    end

And the second if statement (which also has errors), you are just checking if the variable 'OnClicked' is defined, A.K.A if it's not nil.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
21 Dec 2011 02:48 PM
You sometimes shouldn't put it there.

local x = math.random()
print(x)
> some decimal

local x = math.random
print(x)
> some hexadecimal memory address
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
21 Dec 2011 02:49 PM
Basically, the parentheses is telling it to call the function, whereas when you don't it's getting the memory address of it.
Report Abuse
elliesamfish10 is not online. elliesamfish10
Joined: 11 Sep 2009
Total Posts: 764
21 Dec 2011 02:54 PM
Sometimes they are used in editable scripts to show the editors you need to put something in I think :)
Report Abuse
Penguine236 is not online. Penguine236
Joined: 13 Apr 2011
Total Posts: 1303
21 Dec 2011 02:56 PM
@ellie
not even close. They tell the script that an actual function is being called.
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
21 Dec 2011 02:57 PM
Parenthesis show the absence of argument(s). That's all. When you call a function, you use them to shown the absence of arguments, not to call it.

    function sayHello()
        print("Hello!") end
    
    sayHello()

Pyzothon, novice scripter/programmer.
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
21 Dec 2011 02:58 PM
Ugh... my end was in a different place (but it would still work my first way).

    function sayHello()
        print("Hello!")
    end

    sayHello()

Pyzothon, novice scripter/programmer.
Report Abuse
elliesamfish10 is not online. elliesamfish10
Joined: 11 Sep 2009
Total Posts: 764
21 Dec 2011 02:59 PM
Sorry I think im thinking of something else, do you know what I'm thinking of???
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
21 Dec 2011 03:01 PM
Uh...

If you're wondering why we need to use parenthesis in a function like this:

function onTouched()

It shows the absence of arguments, like I said before.

Pyzothon, novice scripter/programmer.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
21 Dec 2011 03:05 PM
Because that's where the argument is supposed to go

function kill(...)
for _,n in pairs({...}) do
for __,p in pairs(game.Players:players()) do
if p.Name:lower()==n:lower() then
pcall(function() p.Character:BreakJoints() end)
end
end
end
end

kill("nate890","someone")

Or you can make a custom pseudo print

function printt(...)
local str={}
for _,s in pairs({...}) do
table.insert(str,tostring(s))
end
print(unpack(str))
end

printt("1","2")


­<'+1 Post. Ujelly?'>
Report Abuse
bikerking200 is not online. bikerking200
Joined: 11 Mar 2010
Total Posts: 5047
21 Dec 2011 03:08 PM
They are there for noobs to go raid leik you.

http://www.roblox.com/Part-Generator-Plugin-V2-item?id=68062295
Report Abuse
bikerking200 is not online. bikerking200
Joined: 11 Mar 2010
Total Posts: 5047
21 Dec 2011 03:08 PM
*Raig*

http://www.roblox.com/Part-Generator-Plugin-V2-item?id=68062295
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