Roblox > Scripting Lessons >

Lesson 8: Connecting Functions

One very usefull feature is that you can connect functions to events. When a function is connected to an event, it is executed when that event is triggered. For example:

function onTouched(brick)
-- insert actions here
end

script.Parent.Touched:connect(onTouched)


The above script runs when the brick that the script is in is touched. Notice the last line of the script. That line connects the function "onTouched" to the touched event of the brick. Different events run the function with different arguments. For example, the touched event runs the function with the one argument containing which brick touched the object. There are many different events. Some are specific to certian types of objects. For example, the Clicked event is specific to the clickdetector object.

Here is a list of some of the events that can be used on every object:

http://wiki.roblox.com/index.php?search=Event

To find other events, you will just have to learn by example or find them on the wiki.

Let me know if there was somthing in this lesson that you didn't understand...

<- Previous Lesson  Next Lesson ->
Updated on Nov 13, 2010 by Ajedi32 (Version 8)
comments powered by Disqus