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

I need an example of what an argument is?

Asked by 9 years ago

Like, what can it be.

0
There is a WIKI Documentary on this specific subject. :) Documentary on Arguments: http://wiki.roblox.com/index.php?title=Arguments TheeDeathCaster 2368 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

I'm not very good at explaining things, but here we go.

First, I'll give some examples

i = math.random(1, 5)

function Hello(arg1, arg2)
    print(arg1)
    arg2.CanCollide = false
end

o = math.floor(0.6666666666666666666) --Equal to 2/3, but we all know when that converts to a decimal it's 0.666...

Hello("HELLO WORLD!", game.Workspace.Part)
print(i)
print(o)

This is a script with three examples.

First one, math.random(). The arguments are inside the parenthesis, what this means is the script doesn't exactly know what to do until it "settles" an argument. In fun terms, lets say you put in math.random(num1, num2), what this is doing is it is asking for a random number from num1 to num2, let's say those numbers are 3 and 15. However, the computer isn't exactly sure what you mean yet, so it argues with itself until you give it the arguments. If there are none, then the computer is practically stuck and returns an error.

Second one, function Hello(arg1, arg2). This time, the arguments are necessary, they are optional, but very handy. If you fire the function using the right values, it can be run easily. When I used Hello("HELLO WORLD!", game.Workspace.Part), it made the first argument "HELLO WORLD!", a string so that the function could print that text to the output, and the second argument was an object, game.Workspace.Part, so the function could make the part Non Collide-able.

Third example is basically like math.random(), except it only has a single argument which can ONLY be a number.

Was that a good explanation?

Ad
Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Arguments can be anything, anything at all.

First, let's start with Parameters:

function funcName(param1, param2)
    print(param1)
    print(param2)
end

Parameters are the local variables (technically upvalues) you create when you define a function. They are the function's 'modifiers'.

Arguments are what you pass into those parameters when you call the function:

arg2 = 125
funcName("argument1", arg2)

Lua is what is known as an 'untyped' language. What this means is that variables are not restricted to holding a certain data type. arg2 in the above code right now holds an integer - 125 - but later on could hold a string, or a Table, or a ROBLOX Object. Because of this, anything at all can be passed into your function's parameters, or even nothing!

Answer this question