Now you can pass in event handling functions by using [OnEvent"EventName"]
as the key.
As an example, here we're connecting a function to our TextButton's Activated
event:
1415161718192021222324252627282930
ZIndexBehavior="Sibling",[Children]={New"TextButton"{Position=UDim2.fromScale(.5,.5),AnchorPoint=Vector2.new(.5,.5),Size=UDim2.fromOffset(200,50),Text="Fusion is fun :)",[OnEvent"Activated"]=function(...)print("Clicked!",...)end},New"TextBox"{Position=UDim2.new(0.5,0,0.5,100),
This works just like a regular :Connect() - you'll recieve all the arguments
from the event. Here, we're just printing them out for demonstration purposes.
If you press 'Play' and click the button a few times, you should see something
like this in the output:
That's all there is to event handling! Fusion will manage the event connections
for you automatically.
Now you can pass in functions using [OnChange"PropertyName"] as the key.
When the property is changed, your function will be called with the new value as
the only argument.
To demonstrate this, here we're printing the text in our TextBox whenever it
changes:
Now, if you press 'Play' and start typing into the TextBox, you should see the
TextBox's contents being printed to the output for each character you type:
With that, you've covered everything there is to know about event and property
change handlers! In later tutorials, this will be useful for responding to user
input.