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

Get/Set Attributes for Other Behaviors

Contents

  • Introduction
  • Getting Attribute Values
  • Setting Attribute Values
  • Example: Revisiting the Level Selector

 

Introduction

Attributes are properties, but beyond that, they store the "state" of a behavior (or set of Events). Sometimes, it's necessary to know the values of attributes from other behaviors, and sometimes, you even want to change their values too.


 

When would this be useful?

  • An enemy might want to know a player's remaining health and pursue them more vigorously if they're low on health.
  • You're creating a bunch of actors all at once, but you want to customize their values on the fly after creating them. For example, you could be making a bunch of enemies with random starting health points.

 

Getting Attribute Values from Other Behaviors

Getting an value of an attribute requires at least 2 pieces of information, sometimes 3.

  • Which Behavior contains the attribute you want?
  • Which Attribute do you want, for that behavior?
  • (If applicable) From which actor do you want to pull the behavior + attribute from?
All of the blocks for getting (and setting) attribute values are located under Behavior > Attributes.


How do you fill in the blanks?

Thanks to Stencyl 2.0, this process is simpler than it was before, but let's step back a bit and understand what each of the blanks mean, even though you won't be typing in these values directly anymore.

  1. The first blank lets you pick the target Actor. (For Scenes, there's no blank at all since it applies to the current Scene)
  2. The second blank takes the internal name of the desired attribute.
  3. The final blank takes the name of the behavior that contains the desired attribute.
     
In Stencyl 2.0, you don't need to type in the attribute and behavior names directly.

Just click on the dropdown arrow for the blank, expand out Attribute Names and pick out the desired Attribute.



Doing this will automatically fill out the field with the Attribute's internal name AND its Behavior's full name. No typing required!



(Aside: The strange name: "ActorEvents_1" stems from the fact that the "Events" page for an Actor or a Scene is represented as a hidden behavior behind the scenes, as you may recall from Chapter 2's lesson on Events.)

 

Setting Attribute Values for Other Behaviors

Setting the value of an attribute is similar to getting it. The only difference is that you have to provide the value you wish to set the attribute to.

Note: Take care to set the values to the appropriate type. That is to say, don't try dumping a text value into a Boolean attribute. This will cause errors at compile-time or run-time.

 

Example: Revisiting the Level Selector

Back in Chapter 4, we made a Level Selector for the Changing Scenes lesson.

In this example, we used an Attribute setter block to assign each level button a number corresponding to the scene it would lead to (and what number it would visually display on the button itself).

Note: The +1 is to account for the fact that computers count, starting from 0, but it would look strange to a regular player to see "Level 0"

 

Summary

  • You can get and set the values of attributes contained in other behaviors.
  • In Stencyl 2.0 and later, just use the dropdowns to fill in the blanks. Don't bother typing in names directly.


Last Updated: 2012-03-31 by Jon

12311 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!
3 Comments
NRead
This seems like it's very out of date. The getter block in Stencyl 2.2 looks nothing like this example. For instance, the first dropdown doesn't let me select a specific actor. I tried creating an actor attribute, but these seem to be scoped locally to the behaviors of the actor I created it for, and I can't use them to reference other actors.
0 3 months, 3 weeks ago
Mystic
I'm trying to draw the current speed of the player's character on the screen. I've got the player's character and the actor for drawing speed, anchored to the screen.
When I'm trying to use "for self, get smth from behavior smth" to get the current speed from the attribute, used in player's actor, I've got nothing, but "null" on the screen. Can't understand what's wrong.

0 10 months, 3 weeks ago
rob1221
I often use the loops under Scene > Actor such as "for each actor of type" when I need one actor to get or set an attribute for another actor. There's probably another section that talks about this but I think it should be mentioned here as well.
0 1 year, 1 week ago



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.