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

What are arguments and permiters? [closed]

Asked by 6 years ago

I have heard these two terms a lot and I have seen them mostly around scripts like function cool (thisiswheretheygousaully). I don't get what the stuff in the ( ) do in most scripts and its ANGERS me so MUCH! People keep saying this permiter makes it for this script something something something and I really just love if someone explained it to me.

Locked by TheeDeathCaster

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

3 answers

Log in to vote
0
Answered by 6 years ago

Parameters are Substitute Variables for a value we don't know the name of, for example:

function createPart(name, size, color) -- Parameters
    local part = Instance.new("Part",game.Workspace)
    part.Name = name -- As you can see, these properties have not been assigned
    part.Size = size -- Anything official. 
    part.BrickColor = color
end

--Now to call the function with arguments

createPart("PartCreatedByFunction", Vector3.new(10,10,10), BrickColor.Green()) -- Must be in order. These are the arguments. 

Arguments are the official value of parameters.

Ad
Log in to vote
0
Answered by 6 years ago

Arguments and parameters are essentially the same thing but I can differentiate the two for you.

An Argument is the data that is passed to the function's parameters like so:

local data = 54 -- This will be the first argument to use for the function's first parameter

Parameters are basically identifiers which you name, that takes data as the input when you call the function

local function theFunction(dataValue) -- dataValue is one parameter for this function
    return dataValue
end

So when you call a function you use the argument(The Data(variable)) where the parameters are like so.

local data = 54 -- This will be the first argument to use for the function's first parameter

local function theFunction(dataValue) -- dataValue is one parameter for this function
    return dataValue
end

theFunction(data)

So this function will return the value of 54 because when we called the function with 'data' which equals to 54.

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Believe it or not, there's a wiki page already on this topic. :P But for this answer, I'll do my own take on it.

<Parameters>

Parameters are where everything begins when starting a new function, whether it's to return a specific value, or to run some code for a specific task. In a nutshell, they're the function SomeFunc(Para1, Para2, Para3) of a function. :P

Here's an example:

function SomeFunc(Parameter)
    return Parameter -- When running the code, it'll return what you gave the function.
    -- What `return` does is that it returns values that you wish to be returned, such as if you want it to return a bool if it found something. (Via using a for loop and a table, then iterating and checking for a specific value.)
end

<Arguments>

In a nutshell, an argument is what you give the function to perform that task. Depending on how you set up your function, you have to give the values/arguments to it as in according to how the function's set up. An example of this would be:

SomeFunc(Argument)
-- In other words, call the function and give it the value. :P

TL;DR Arguments are what you give the function. XP

<Side Note: Tuples>

Ah, tuples. The most very interesting in my opinion. It allows you to set up any number of parameters you need, but requiring to use a table to be able to get its values (from my experience). An example would be:

function SomeOtherFunc(...) -- `...` is a tuple, which has the ability to use numerous amounts of parameters.
    print(table.concat({...}, ' '))
    -- `table.concat` is a bit hard to explain, but it takes a table, and then adds a value in while compiling the values into the table, such as the result below vvv
end

SomeOtherFunc('hello', 'how', 'are', 'you?') -- 'hello how are you?'

<The upside and downside of a tuple>

Tuples are a good way to get a numerous amount of parameters, but it comes with its downside. The major one is that if you need any "main parameters" that're required, they can't be after the tuple, otherwise they'll be apart of the tuple as well.

function SomeOtherFunc2(..., Parameter) -- `Parameter` is, well, the parameter in this example, showing the downside of putting it after a tuple.
    print(table.concat({...}, ' '))
    print(Parameter, 'can after tuple')
end

SomeOtherFunc2('hai', 'derp')
--Result: hai derp
--Result:

<Solution to this>

The only solution to prevent this is to put your required parameters before the tuple, to put short. :P An example of this would to be:

--           vvv B/c I've made quite a few functions. XP
function ImMakingALotOfFuncs(Parameter, ...) -- Putting the `Parameter` before the tuple `...`, resulting in two different results instead of with the code before.
    print(table.concat({...}, ' '))
    print(Parameter)
end

ImMakingALotOfFuncs('Hello World!', 'derpderpderp')
--Result: derpderpderp
--Result: Hello World!

I hope this helped! ^^ Please let me know if you have any questions regarding this.

<EDIT>

At the request of the OP, here's some links to answer those questions:

  1. Return (Wiki page) - Returns values given to it.

  2. Tuples (Wiki) (Wikipedia) - As explained, it allows you to use numerous parameters as you want/need; the only downsides (from experience) is that you require a table, and that you can't have main parameters after it.

  3. Nutshell (Idioms) - Another way of saying "in other words", or to put simply.

0
While I appretiate everyones answers, I don't any of the terms you used so none of it makes sense.. For example, whats a "nutshell", whats a "tuple", what does the script "return" do. ShootingLeo 35 — 6y
0
^ Ok, posted some links, and updated explanations with some things. Although, please do a bit of research next time. :P You don't want your question to be seen as `Not Constructive`. :/ TheeDeathCaster 2368 — 6y