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

Do Events provide built-in arguments?

Asked by
emite1000 335 Moderation Voter
9 years ago

I have done some testing, and after findings such as this and example 2, I have pretty much come to the conclusion that many Events have built-in values that they can give to arguments.

However, I was not able to find anything on the Wiki about this. Can anyone confirm this claim for me, and possibly add any additional information they know about it (such as which Events have arguments to give)

Example 2: In a script inside a Part, write:

function Frap(Goo)
    Goo.BrickColor = BrickColor.new("Camo")
end
script.Parent.Touched:connect (Frap)

When the player touches the Part, whatever touched it will turn to the color Camo. Even though Goo was never actually defined when the function was called, Touched gave a value to it.

0
Yes. Many events have built in parameters. Perci1 4988 — 9y
0
If you look at the wiki page for the event it does show what parameters it has. NotsoPenguin 705 — 9y
0
Most of these things we don't think about. We just take them for granted because they just work. Tkdriverx 514 — 9y
0
No, not everything has it's own parameter. For example Mouse1Click doesn't have a parameter for the player. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

It's kinda like this code:

function PrintMe(messagetoprint)
    print(messagetoprint)
end

PrintMe("This is a test")--It will print "This is a test". connect basicly just does this whole argument thing by itself. Like a little mini-script helper that just comes and gives you the arguments without you needing to find them yourself.

I think that events do have their own arguments because of the :connect() part. Compair Script1 to 2. (I know script 2 is wrong. It's just to give an idea.) Script 1

script.Parent.Touched:connect(function(hit) --So easy. 3 lines.
    hit.BrickColor = BrickColor.new(0) --Black
end

Script 2

hitparts = {} --21 lines. ermgosh.
local count = 0

while wait() do
    for _,parts in pairs(workspace:GetChildren()) do
        if parts:IsA("Basepart") and math.abs(parts.Position.X)-math.abs(script.Parent.Position.X) == 1 or math.abs(parts.Position.Y)-math.abs(script.Parent.Position.Y) == 1 or math.abs(parts.Position.Z)-math.abs(script.Parent.Position.Z) == 1 then
            count = count+1
            hitparts[count] = parts
        end
    end
end

function onTouch(hit)
    hit.BrickColor = BrickColor.new(0) --Turn the part to black
end

while wait() do
    for _,touched in pairs(hitparts) do
        onTouch(touched)
    end
end


The connect is a RBXScriptSignal. When you use the connect, if you're doing a touched script, it would make a RBXScriptConnection object. This object returns the part you touched in this case.


Yes, events do have their own arguments thanks to RBXScriptConnection!

0
Does every Event have its own argument? Even ones like ChildAdded? emite1000 335 — 9y
Ad

Answer this question