The CreatesEvent property is a property which controls whether a Screen or Entity will raise an event whenever a given variable is set. For example, you may want to update a health bar object any time a Player’s CurrentHealth variable is set.
How to use CreatesVariable
For this tutorial I’ll use a Width variable that we’ll create:
- Expand your Entity and find the “Variables” tree item
- Right-click on Variables
- Select “Add Variable”
- Select “Create a new variable”
- Verify the type is “float”
- Enter the name “Width”
- Click OK
Now that the Width variable has been created, let’s make an event for whenever the variable is set. You can do this one of two ways:
The easiest way to do this is to drag+drop the variable onto the “Events” tree node
- Push and hold the left mouse button over the “Width” variable
- Move the moue down to the Events tree item in the same Entity
- Release the mouse button
Setting CreatesEvent in the Variable’s properties
Instead of drag+dropping, you can manually set up the event through Glue as follows:
- Create a variable. In this tutorial I’ll use a new float variable called “Width”
- Select the newly-created variable.
- Set the CreatesVariable variable to true:
Once a variable has its CreatesEvent set to true, you will need to tell Glue to create a function that will be called when this variable is set (the drag+drop method shown above automatically does this for you). To do this:
- Right-click on Events
- Select Add Event
- Select to Expose an existing event
- Select the event for your variable. For example, if your variable is called “Width” then select the AfterWidthSet event.
- Click OK
Editing the Event
If this is the first event you have created for the selected Screen/Entity, Glue may notify you that it has created a new file. The file will be called
You can now code the contents of the event in Glue, or in Visual Studio.
To edit the code in Glue, select the event in Glue and a code window will appear:
To edit the code in Visual Studio, open your project, and navigate to the Screen or Entity code file in Visual Studio. Expand the item and you will see the Event.cs file:
Viewing events in real time
GlueView has a built-in code parser/interpreter. Therefore, if you write event code in Glue or Visual Studio, GlueView will automatically parse and apply the event code in real time.
To see this, first we’ll create an AxisAlignedRectangle in Glue:
- Select your Entity (in this case UiFrame)
- Right-click on Objects and select “Add Object”
- Select “FlatRedBall or Custom Type”
- Select “AxisAlignedRectangle” in the list
- Click OK
If you open GlueView you will see the AxisAlignedRectangle:
Next we’ll add some code to modify the AxisAlignedRectangle when Width is set. To do this:
- Select the AfterWidthSet event in Glue, or open up Visual Studio and navigate to your Entity’s Event.cs file (which in this case would be UiFrame.Event.cs)
- Add the following code:
C#1this.AxisAlignedRectangleInstance.Width = this.Width;
- Select the “Width” variable in the Entity
- Set the value to 128
- Notice that GlueView automatically updates the size of the rectangle according to the code you have written in the event:
Using Events in Custom Code – Advanced
Note that the steps above are all that is necessary to create an event and use it in custom code. However, since events created by Glue are actually events ( the C# keyword ), you can use the created events in your custom code inside the object that defines the event, or you can += the event on any instance.
Once a variable has CreatesEvent set to true, the class containing the variable contains two events – one which is called before the variable is set and one after the variable is set. The names of the events are:
- Before[VARIABLE NAME]Set – for example BeforeScaleXSet
- After[Variable Name]Set – for example AfterScaleXSet
If you expose the event, then you simply have to open the ELEMENTNAME.Event.cs file to code right in the event. Or you can += it in custom code.
In custom code simply += a method as shown in the following:
private void CustomInitialize()
this.AfterWidthSet += new EventHandler(CustomWidthHandler);
void CustomWidthHandler(object sender, EventArgs args)
// Do whatever you want whenever Width is set