4
The core of DSE is the event dispatch system. This system is
5
responsible for calling Ren'Py code that implements each of the
6
events. The event dispatcher chooses a list of events that should be
7
run during a given period, and then is responsible for calling each of
8
those events in turn until either all events are exhausted, or one of
9
the events indicates that the period should come to an end.
14
An event consists of a block of Ren'Py code. The name of the event
15
is the name of the label that is called to execute that event. There
16
are three ways of returning from an event. Simply executing a 'return'
17
statement will end the event, and activate any later event in the same
18
period. Jumping to events_end_period will end the current period,
19
ignoring any future-scheduled event. Jumping to events_skip_period
20
will both end the current period, and cause the next period to be
23
Events are declared by calling the event(name, ...) function from
24
inside an init block. This function takes a variable number of
25
arguments. The first argument is always the name of the event, which
26
is also the label that is called to start the event. The second and
27
later arguments are conditions that must be true for the event to
28
occur. These conditions may either be python expressions in strings,
29
or the result of one of condition functions given below. The event
30
function takes one keyword argument, which gives the priority of the
31
event. Events with a smaller priority number are considered before
32
those with a larget priority number, with the default priority being
35
Consideration of events occurs in two phases. First, the conditions
36
are evaluated on each event. If any condition is false, the event is
37
discarded, otherwise it is added to the event list. Then, the list is
38
filtered and random elements chosen such that only one event is in
39
each choice group, for the events that are in choice groups. The
40
events are always kept in priority order, with lower numbers being
41
higher priority. The first event in the list is recorded as being
42
executed, and then executed. Execution continues until all events are
43
exhausted, or the period is forced to end.
45
The following condition functions ship as part of the DSE.
49
Returns True until the event has been executed once, and then
50
returns False. It can be used to ensure that the user will only see
55
Returns True if there are no higher-priority events scheduled. Use
56
this on a very-low-priority event that should only occur if no
57
high-priority events occur.
61
Returns True if no higher-priority events have been . If it returns
62
True, it prevents all other events from being considered.
64
event.happened(*events)
66
Supply this function with one or more events names (strings). It
67
returns true if those events have happened already, at any time in
70
event.depends(*events)
72
Supply this function with one or more events names (strings). It
73
returns true if those events have executed, yesterday or before.
75
event.random(probability)
77
Probability is a float between 0.0 and 1.0. Returns True with the
78
supplied probability, each time it is evaluated. (Each period.)
80
event.choose_one(group, count=1)
82
This defines a group from which only one event can be chosen. DSE
83
randomly picks one of the elements from the group such that all of
84
the other conditions are True. An event can only be in one group at a
85
time. (Objects returned from here should not have operators applied
86
to them.) The count is used to determine the relative likelyhood of
87
an event in a group being chosen, with a count of 10 being 10 times
88
more likely then a count of 1.
90
The objects returned from condition functions can be combined using
91
the and, or, and not operators. For example:
93
event('bachelor_party', event.depends('engaged_a') or event.depends('engaged_b'))
98
There are a few entry points that are used in main to call the event
99
dispatcher. First of all, there is the function check_skip_period(),
100
that should be called to determine if a period should be run at
101
all. The Ren'Py label events_run_period should be called to run a
102
single period. Finally, the Ren'Py label events_end_day should be
103
called to end a day. Ending a day stops skipping periods, and also
104
changes the events that are considered executed by event.depends.