Events
In real games, it is important to listen to changing conditions, such as a user clicking a button, or a score increasing. In programming, this is done using events. Powerlang allows you to connect to predefined events using the event directive.
The structure of an event directive is usually as follows:
EventName
represents the name of the event you want to connect to, and inside brackets we can pass arguments to the event and receive outputs related to it.
For example, we can listen to changes to Lighting like this:
So if anyone changes any Lighting property, for example the clock time or the brightness of the game, we will get an output about it.
It is also possible to pass arguments to events like this:
Now this event will only trigger when the Brightness property is changed.
It may be tempting to pass the instance as an argument, especially when viewing at the Event Table at the end of this article, like so:
event PropertyChanged(game.Lighting, "Brightness", newValue)
This is not currently supported, so please do not do it.
Service events
As you may have seen by the previous example, the example events "AnyPropertyChanged" and "PropertyChanged" have to be attached to an Instance, in our case game.Lighting
. However there are some events that do not need to be attached. These are called service events. An example of a service event would be the player input events: LeftMouseDown
, KeyDown
, JumpRequest
, etc.
Here's an example of printing "Hi!" when the user presses the E key on their keyboard:
All events (table)
For your convenience, here is a table with all events in Powerlang. Be sure to check this table each time you're unsure of an event name.
Use Ctrl+F to find the event you need. Remember that some of these only work on the server, and some of these only work on the client (but the majority should work in both places).
For service events, the first input is the instance that the event must be attached to.
Last updated