Skip to content
Al'rind edited this page Jul 13, 2015 · 3 revisions

Sometimes, it happens that we want to apply an action on specific events at run. For instance, we would like the events n°1 and n°2 to jump when we click on them.

It is obviously possible to do such a thing with conditions; however, all commands that are doing actions on an event can, instead of taking their ID (and thus being applied on only one event), take a particular construction which is called a selector.

Let's take this command, for instance:

mouse_click_event?(events)

Returns true if the mouse click one of the events of the given selector.

Name|Type|Description --- | --- | --- events|Selectors|Events' selector

This command returns true if the mouse has clicked on the event given as argument, right when the command is called. This expression is totally valid: mouse_click_event?(1) and will return true if a mouse's click has occured on the event n°1 (false otherwise).

Now, let's suppose that we want to perform the same action (so, knowing if we have clickedà on event n°1, n°2 or n°3 ? You will probably say that this is an easy thing and that we could do something like that: If Script : mouse_click_event?(1) OR mouse_click_event?(2) OR mouse_click_event?(3) but this is not quite handy. In order to specify all the events on which we want to apply a peculiar action, we can pass more than an integer as the events argument (Yes, the integer is the most primitive selector).

Composing a simple selector

Beyong the use of an integer to reference an event, we have the Product selector. With it, we can select a list of events: events(id1, id2, etc.). We can give it an infinite list of events and it will only take the ones which are truely existing. From that moment on, if we want to know if the event n°1, n°2 or n°3 and also the hero (event n°0) has been clicked on, we could use this selector: events(1, 2, 3, 0); which will result in the end in this: mouse_click_event?(events(1, 2, 3, 0)).

Generating a selector

The simple selector forces you to clearly specify all the IDs on which you want to perform an action. But is also possible to generate selector, just like that: events{|id| generator}. For instance, in order to generate a selector containing all the events whose ID is above ten: events{|id| id > 10}. It is also possible to bind the generator's condition with logical operators; for instance: events{|id| id > 15 and id < 100} will provide an events' selector whose events'ID is greater than 15 and less than 100.

RME commands' use

Obviously, you can use RME commands inside a selector's generator. For instance: events{|id| event_x(id) > 14 and event_y(id) > player_y}, will generate a selector of events whose X position is greater than 14 and which are located under the hero.

Combination of a simple selector and a generator

It is possible to both select and combine, for instance: events(1,2,3){|id| event_x(id) > 15}, will produce a selector containing the events n°1, n°2 and n°3 but also every events whose X coordinate is greater than 15.

Universal selector

It is also possible to create easily a selector which contains all the events and the hero. One way of doing such a thing woukd be: events{|id| id >= 0} in order to take all events whose ID is greater than or equal to 0. However, there is an handier selector: all_eventsorevents(:all_events)`. We better use the first one.

Selectors for a single event

There are two selectors which return only one event found in the events' list: once_events{|id| generator} which will return the ID of the first corresponding event; and once_random_event{|id| generatorr} which will return an event's ID randomly taken from the events corresponding tothe generator. For those two commands, if no event fits the selector, they will return nil.

Excluding events

Sometimes, generators take too much events and we would like to exclude some of them. In order to do that, we can use the not keyword. For instance: all_events.not(0) will return a selector containing all events excepting the hero's one. Just as simple selectors, we can pass an infinity of identifiers to not. For instance: events{|id| id%2 == 0}.not(2, 4, 16, 38) is a selector which will take all event whose ID is an even number excepting 2, 4, 16 and 38. The not method can also exclude with an exclusions' generator. For instance: all_events.not{|id| event_x(id) < player_x} is a selector which will take all the events, excepting the one which are located at hero's left. And as for simple generators, it is also possible to combine an event's list with a generator. For instance: all_events.not(0){|id| id > 13}. (If you still don't understand this one, you better read once more this page !)

This command does not work on single selectors !

Convenient trick

Usually, it happens that selectors become "huge" (because we want to filter events), don't hesitate to store them in variables. For instance:

# A selector containing all events which are
# located on the same vertical axes as the hero
# and whose identifier is an odd number
V[1] = events{ |id|
   (event_y(id) == player_y) and (id%2 != 0)
}.not(0)
Clone this wiki locally