skript-reflect
2.x
2.x
  • skript-reflect
  • Getting Started
  • Basics
    • Reading Javadocs
    • Importing classes
    • Running Java code
    • Handling events
    • Utilities
  • Advanced
    • Error handling
    • Loading external libraries
    • Custom syntax
      • Effects
      • Conditions
      • Expressions
      • Events
    • Computed Options
    • Reflection
      • Proxies
      • Sections
    • Experiments
  • Code Conventions
  • Frequently Asked Questions
Powered by GitBook
On this page
  • Flag local
  • Event identifier
  • Option event-values
  • Section parse
  • Section check
  • Calling the event
  • Extra data

Was this helpful?

  1. Advanced
  2. Custom syntax

Events

PreviousExpressionsNextComputed Options

Last updated 3 years ago

Was this helpful?

[local] [custom] event %string%:
  pattern: # pattern, required
  event-values: # list of types, optional
  parse:
    # code, optional
  check:
    # code, optional
[local] [custom] event %string%:
  patterns:
    # patterns, one per line, required
  event-values: # list of types, optional
  parse:
    # code, optional
  check:
    # code, optional

Flag local

Specifying that an event is local makes the event only usable from within the script that it is defined in. This allows you to create events that do not interfere with events from other addons or scripts.

Local events are guaranteed to be parsed before other custom events, but not necessarily before events from other addons.

Event identifier

The string used in the trigger line represents the identifier of this custom event. This identifier should be used for .

Option event-values

The event-values specified here will be available in the event, either as a default expression (message "Hello" without the need for to player) or as a normal event-value (event-player / player)

Section parse

Code in this section is executed whenever the event is parsed. This section may be used to emit errors if the effect is used in an improper context.

Local variables created in this section are copied by-value to other sections.

event "example":
  pattern: example
  parse:
    set {_test} to 1
    continue
  check:
    # {_test} always starts at 1 here
    add 1 to {_test}
    # broadcasts 2
    broadcast "%{_test}%"
    continue

Section check

Code in this section is executed just before the event is called. This section may be used to stop the event from being called if certain conditions are met.

Calling the event

You can get an instance of a custom event using the following expression:

[a] [new] custom event %string% [(with|using) [[event-]values] %-objects%] [[and] [(with|using)] data %-objects%]

You can then call it using the following effect:

call [event] %events%

If you want to check if an event has been cancelled, after you've called it, you can use the following condition:

%events% (is|are) cancelled
%events% (isn't|is not|aren't|are not) cancelled

Extra data

[extra] [event(-| )]data %string%

In the syntax above, %string% is the index. This doesn't have to be plural, but can be.

If this section is included, you must also if the event was parsed successfully.

If this section is included, you must also if you want to event to be called.

The first argument should contain the name of the event you want to call. The second argument is a list variable, with each element of the following format: {list::%type%} = %value%. The third argument is almost the same, the only difference is that %type% is replaced with a string, which is just the index. The first list variable is for , while the second is for .

If the event-values aren't enough for your desire, you can make use of the extra data feature. The syntax for adding event-values to a custom event is explained in , and how to call an event with them is explained in In the event itself, you can get the extra data with the data expression:

It may look fancier to create a custom expression instead of using extra data. To do so, you need to call event.getData(%string%) to get the data value. See the usable in sections in , and .

calling the event
the event-values
the extra data
the event-values option
calling the event
conditions
expressions
continue
continue
effects