Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When you set a function, what happens when you put something in the brackets?

Asked by
igric 29
7 years ago

for an exampe

local function hi([somthing here])
print("What does the bracket means D: I can't find my answer on the internet.")
end
0
Brackets after the "function" - function() igric 29 — 7y

2 answers

Log in to vote
0
Answered by
iRexBot 147
7 years ago
Edited 7 years ago

The bracket for function() allows arguments to added in it. Example:

function(arg1)
    print(arg1)
end
arg1("Hello World!")

The function would print Hello World! This use can allow developers to quickly run codes without copy and pasting it. Also this is very important for modules scripts too.

======After editing===========

A more complex situation for this would be a script requiring a module script to summon a part Exmaple:

Module Script:

local module = {}
    function module:SpawnPart(position, partcolor)
        local part = Instance.new("Part")
        part.Position = position
        part.Color3 = partcolor
        print("Added part!")
    end
return module

Script:

local module = require(moduleScript)
module:SpawnPart(Vector3.new(0, 0, 0), Color3.fromRGB(0, 50, 100))
1
Thanks, but can you give me an example on how you use it in one more complex script. :) igric 29 — 7y
0
Ok let me get one iRexBot 147 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I would suggest searching up what arguments and parameters are because they play a major role in scripting. But I'll try to do my best to explain it.

--// Parameters are values inside of the brackets when you create the function

local function printingfunction(x)
    print(x)
end

--// Arguments are the syntax used when you call your function

printingfunction("Hello World!")

--> Console would print Hello World!

This is a simple example of arguments and parameters. You can create more complex functions with multiple parameters and arguments

Sources: http://wiki.roblox.com/index.php?title=Arguments_and_parameters

Answer this question