Event: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Legend26
Two random stray "]" characters
>Capacitor
Added details about Events upon Quenty's request. May need revisions.
Line 1: Line 1:
__TOC__
{{Disambig
{{Disambig
|{{type|RBXScriptSignal}}, the class of events used by ROBLOX {{type|instance=Instance|Instances}}.
|{{type|RBXScriptSignal}}, the class of events used by ROBLOX {{type|instance=Instance|Instances}}.
|[[File:Event Icon.png]] [[Event (Event)|Event]], an event of the {{type|instance=BindableEvent}} object.
|[[File:Event Icon.png]] [[Event (Event)|Event]], an event of the {{type|instance=BindableEvent}} object.
}}
}}
== Introduction ==
An Event is similar to properties - but instead of holding a variable, events "Fire" when a cetain condition is met. Events are found in most objects, and can be used to fire a specific function upon an event occuring, for example:
<code>
function partTouched()
print("Something has touched the brick!");
end
local part = game.Workspace.Part
part.Touched:connect(partTouched)
</code>
As seen in the above example, upon a physical object colliding with Part, the text "A brick named <part that collided> has touched the brick!" is printed to the output.
== Arguments ==
Most events have at least one argument, in the next example, we will remove any objects that collide into game.Workspace.Part.
<code>
local part = game.Workspace.Part
function collision(hit)
hit:Destroy()
end
part.Touched:connect(collision)
</code>
Being that the [[Touched]] event carries one argument, the object that collided into the brick. Lets try another example, this time with the [[Changed]] event. In this example, any changes to Part's properties will be printed to the output.
<code>
local part = game.Workspace.Part
function somethingChanged(property)
print("The " .. property .. " property has been changed!");
end
part.Changed:connect(somethingChanged)
wait(3)
part.Name = "Brick"
</code>
The above example will print "The Name property has been changed" after about three seconds of the script running.

Revision as of 21:35, 9 March 2012

You might be looking for one of these pages:


Introduction

An Event is similar to properties - but instead of holding a variable, events "Fire" when a cetain condition is met. Events are found in most objects, and can be used to fire a specific function upon an event occuring, for example:

function partTouched() print("Something has touched the brick!"); end

local part = game.Workspace.Part part.Touched:connect(partTouched)

As seen in the above example, upon a physical object colliding with Part, the text "A brick named <part that collided> has touched the brick!" is printed to the output.

Arguments

Most events have at least one argument, in the next example, we will remove any objects that collide into game.Workspace.Part.

local part = game.Workspace.Part

function collision(hit) hit:Destroy() end

part.Touched:connect(collision)

Being that the Touched event carries one argument, the object that collided into the brick. Lets try another example, this time with the Changed event. In this example, any changes to Part's properties will be printed to the output.

local part = game.Workspace.Part

function somethingChanged(property) print("The " .. property .. " property has been changed!"); end

part.Changed:connect(somethingChanged)

wait(3) part.Name = "Brick"

The above example will print "The Name property has been changed" after about three seconds of the script running.