Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
Level: Intermediate

Custom Events

Note: In past versions, Custom Events were known as "Messaging." We changed the name to make its intent clearer and easier to undestand. Functionality-wise, nothing has changed.

 

Contents

  • What are Custom Events?
  • Defining Custom Events
  • Triggering Custom Events
  • One Recipient vs. All
  • Making the Custom Event Configurable
  • Custom Events vs. Custom Blocks

 

What are Custom Events?

Custom Events are special kinds of events that happen only when you tell them to happen.

Why would you want to do this?

  • Reuse Logic. If you're finding that you're copying and pasting the same code, you could stick it into a Custom Event and trigger that Custom Event instead.
  • Allow other behaviors to cause stuff to happen
     
Aside: In programming terms, Custom Events are equivalent to the concept of "messaging" or "indirect invocation" - they aren't quite the same as function calls since you aren't always specifying a receiver. There can be as few as 0 receivers or infinitely many.

 

Defining Custom Events

1) Inside the Behavior Designer, go to Add Event > Advanced > Custom Event

2) Type something into the blank. This is the text that will cause this Custom Event to trigger.

That's it! Now fill out what you want to happen inside the event.

 

Triggering Custom Events

Custom Events are triggered by any one of the blocks under Behavior > Triggers. The act of telling a Custom Event to happen is called triggering.

To trigger an event, put in the text you stuck into the blank when defining the event.

That's all there is to triggering Custom Events.

You might be curious about what the difference is between the "all behaviors" vs. "(one) behavior" variants though...

 

One Recipient vs. All

As you have may noticed, triggering Custom Events can be done directly (one behavior) or indirectly (all behaviors). This to say:

  • You can specify exactly which behavior you're targeting.


     
  • You specify no target, so it attempts to trigger the event for all behaviors for a particular Actor or Scene.


     
Note: If a behavior doesn't have a Custom Event, and you try to trigger it, nothing happens. It's safely ignored.


When would specifying no target ("all behaviors") be useful?

  • A bunch of behaviors happen to receive the same event, and you want to target them all at once.
  • You don't feel like typing in the target behavior, so you target them all. Besides a minor performance penalty, there's nothing wrong with this.

 

Making the Custom Event Configurable

In some rare instances, you may find a need to make a Custom Event configurable. Which is say that you want to stick a Text Attribute into the blank.

You can do this, and as you'd expect, the text for Custom Event becomes configurable.

Warning: However, it is not advised that you change the value of the Text Attribute at runtime during the game. The Custom Event may break if you do this.

 

Custom Events vs. Custom Blocks

Custom Events and Custom Blocks overlap somewhat in use case. Custom Events differ from Custom Blocks in one key area: they don't accept "parameters." If you need to pass some data in, you have to use a Custom Block instead.

We've got an entire article devoted to Custom Blocks.

 

Summary

  • Custom Events are events that you trigger yourself.
  • You define the text that triggers the event.
  • Generally speaking, it's easier and simpler to just target all behaviors rather than specifying a specific recipient.


Last Updated: 2012-04-01 by Jon

9307 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game, please ask a question on the forums. Thanks!
0 Comments
Be the first to make a comment!



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.