|
|
(7 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| __TOC__
| | #redirect [[RBXScriptSignal]] |
| | |
| {{Disambig
| |
| |{{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.
| |
| }}
| |
| | |
| == Introduction ==
| |
| | |
| An Event is similar to a Property - but instead of holding a variable, events "fire" when a cetain condition is met. When an event fires, all the "handlers" which are connected, or bound, to the event are executed. Events are found in most [[Instance]]s.
| |
| | |
| {{lua|=
| |
| | |
| local part = game.Workspace.Part
| |
| part.Touched:connect(function(p)
| |
| print("Hit by " .. p.Name)
| |
| end)
| |
| </code>
| |
| | |
| In the example above, an event handler is bound to the {{`|Touched}} event of a part, which prints out "Hit by <part that collided>" when the event fires, i.e. the brick is touched.
| |
| | |
| == 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.
| |