File: eventchain.md

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (96 lines) | stat: -rw-r--r-- 2,380 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
EventChain
==========

An EventChain is an [event](/engine/event) that triggers other events sequentially, as in a chain of events.

Factory
-------

#### Events.EventChain

`Events.EventChain(chain)`

Spawns an EventChain.

*Arguments*

* `chain`: [Array](/reference/array) object. A list containing zero or more events.

*Returns*

A new EventChain that triggers the specified events, one at a time. The first time the EventChain is triggered, the first event of the `chain` will be triggered. The second time the EventChain is triggered, the second event of the `chain` will be triggered, and so on.

**Note:** if the EventChain ever triggers its last event, from that moment onwards it will always trigger its last event (unless you make it loop).

*Example*

```
// EventChain example
// This is a level setup object. Make sure to link it in your .lev file!
using SurgeEngine.Level;
using SurgeEngine.Events.EventChain;
using SurgeEngine.Events.FunctionEvent;

object "My Level Setup"
{
    fun constructor()
    {
        Level.setup({
            "Switch": {
                "sticky": false,
                "onActivate": EventChain([
                    FunctionEvent("Print").withArgument("First time"),
                    FunctionEvent("Print").withArgument("Second time"),
                    FunctionEvent("Print").withArgument("Third time"),
                    FunctionEvent("Print").withArgument("Enough!")
                ])
            }
        });
    }
}
```

Functions
---------

#### willLoop

`willLoop()`

Make the EventChain loop. When the last event of the chain is triggered, the next event to be triggered will be the first one.

*Returns*

The EventChain object.

*Example*

```
// Triggering Alternating Events
// This is a level setup object. Make sure to link it in your .lev file!
using SurgeEngine.Level;
using SurgeEngine.Events.EventChain;
using SurgeEngine.Events.FunctionEvent;

object "My Level Setup - Alternating Events"
{
    fun constructor()
    {
        Level.setup({
            "Switch": {
                "sticky": false,
                "onActivate": EventChain([
                    FunctionEvent("Print").withArgument("Triggered Event A"),
                    FunctionEvent("Print").withArgument("Triggered Event B")
                ]).willLoop()
            }
        });
    }
}
```

#### call

`call()`

Triggers the event.