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

How is it that a game can know a parameter of a function without assigning it?

Asked by 5 years ago
function RayIgnoreCheck(hit, pos)
    if hit and (hit.Transparency > 0 or hit.Name == "Bullet" or hit.Name == "Handle" or hit:IsDescendantOf(char)) then
        return true
    end
    return false
end

so you know how it says if hit but how does it know how does the game know what hit is and what pos is?

0
For a ray something like "local hit, position, normal = Workspace:FindPartOnRay(ray, ignore)" where hit is the part that was hit, position is the center of the ray and Normal returns normal to the surface that was hit (if hit). The ignore would obviously be defined locally above this line. ABK2017 406 — 5y
0
Methods (:) automatically pass `self` which is responsible for why it knows the parameter. EpicMetatableMoment 1444 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

When you run a function, you may want to add stuff to the stuff Inside the function... For that reason there are parameters!!

here is an example:

local function printText(Some_Random_Text)
    print(Some_Random_Text)
end

printText("Hello world")

Like I said, you need to define whatever is in the parenthesis for later use.

More examples:

local function random(a)
    print(a)
end

random(math.random(0,10))

In this example, math.random is the parameter.

Basically parameters are a random variable that soon gets defined when you call the function.

https://www.robloxdev.com/articles/Arguments-and-Parameters

Here is some more information ^^

Ad

Answer this question