Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

2 comments

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.

0

Methods (:) automatically pass self which is responsible for why it knows the parameter.

1 answer

✓ Accepted answer

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 ^^

This discussion is preserved as it was. New answers, comments, and votes are closed.