@@ -3,19 +3,23 @@ local flow = require "ludobits.m.flow"
3
3
function init(self)
4
4
msg.post(".", "acquire_input_focus")
5
5
flow(function()
6
- print("1 Flow has started")
6
+ print("Flow has started")
7
7
8
8
-- wait until 0.5 seconds have elapsed
9
9
flow.delay(0.5)
10
- print("2 flow.delay() half a second has elapsed")
10
+ print("flow.delay() half a second has elapsed")
11
11
12
12
-- wait until 10 updates/frames have been registered for this flow
13
13
flow.frames(10)
14
- print("3 flow.frames() 10 frames have elapsed")
14
+ print("flow.frames() 10 frames have elapsed")
15
+
16
+ print("Waiting for input")
17
+ local action_id, action = flow.until_input_released(hash("touch"))
18
+ print("flow.until_input_released()", action_id)
15
19
16
20
-- load a collection proxy and wait for it to become loaded
17
21
flow.load("#a_proxy")
18
- print("4 flow.load() a_proxy loaded")
22
+ print("flow.load() a_proxy loaded")
19
23
20
24
-- the running flow will wait for this flow to finish
21
25
flow(function()
@@ -25,66 +29,66 @@ function init(self)
25
29
flow.until_true(function()
26
30
return go.get_position().x == 500
27
31
end)
28
- print("5 flow.until_true() go.animate() done")
32
+ print("flow.until_true() go.animate() done")
29
33
30
34
-- flows can be nested to any depth
31
35
flow(function()
32
36
flow.delay(1)
33
37
34
38
flow.load("#b_proxy")
35
- print("6 flow.load() b_proxy loaded")
39
+ print("flow.load() b_proxy loaded")
36
40
end)
37
41
38
42
flow.go_animate(".", "position.y", go.PLAYBACK_ONCE_PINGPONG, 500, go.EASING_INOUTCUBIC, 1, 0)
39
- print("7 flow.go_animate() done")
43
+ print("flow.go_animate() done")
40
44
end)
41
45
42
46
-- unload a collection proxy and wait until it is unloaded
43
47
flow.unload("#a_proxy")
44
- print("8 flow.unload() a_proxy unloaded")
48
+ print("flow.unload() a_proxy unloaded")
45
49
46
50
-- the running flow will not wait for this flow to finish
47
51
flow(function()
48
- print("10 Parallel flow starting")
52
+ print("Parallel flow starting")
49
53
flow.delay(2)
50
- print("11 The outer flow did not wait for me")
54
+ print("The outer flow did not wait for me")
51
55
msg.post("#", "fooo")
52
56
flow.delay(0.2)
53
57
msg.post("#", "abc")
54
58
flow.delay(0.2)
55
59
msg.post("#", "booo")
56
60
end, { parallel = true })
57
61
58
- print("9 This flow will continue to run without waiting for the parallel flow to finish")
62
+ print("This flow will continue to run without waiting for the parallel flow to finish")
59
63
60
64
-- wait for any message (the message will be posted by the parallel flow created above)
61
65
local message_id, message, sender = flow.until_any_message()
62
- print("12 flow.until_any_message()", message_id, message, sender)
66
+ print("flow.until_any_message()", message_id, message, sender)
63
67
64
68
-- wait for a specific message (the message will be posted by the parallel flow created above)
65
69
local message_id, message, sender = flow.until_message(hash("booo"))
66
- print("13 flow.until_message()", message_id, message, sender)
70
+ print("flow.until_message()", message_id, message, sender)
67
71
68
72
-- wait until a callback is invoked
69
73
-- in this case we make a http.request call and wait for the callback
70
74
local self, id, response = flow.until_callback(function(callback)
71
75
http.request("http://www.google.com", "GET", callback)
72
76
end)
73
- print("14 flow.until_callback() http.request() with callback done", response.status)
77
+ print("flow.until_callback() http.request() with callback done", response.status)
74
78
75
79
-- waiting for a callback must also work when the callback is
76
80
-- invoked immediately (as opposed to the result of some async operation)
77
81
local foo, bar = flow.until_callback(function(callback)
78
82
callback("foo", "bar")
79
83
end)
80
- print("15 flow.until_callback() immediate callback", foo, bar)
84
+ print("flow.until_callback() immediate callback", foo, bar)
81
85
82
86
flow.load("#a_proxy")
83
- print("16 flow.load() a_proxy loaded")
87
+ print("flow.load() a_proxy loaded")
84
88
85
89
-- play a sprite animation and wait until it is done
86
90
flow.play_animation("#sprite", "green_walk_once")
87
- print("17 DONE")
91
+ print("DONE")
88
92
end)
89
93
90
94
flow(function()
@@ -110,8 +114,5 @@ function on_message(self, message_id, message, sender)
110
114
end
111
115
112
116
function on_input(self, action_id, action)
113
- if action.released then
114
- print("stopping")
115
- flow.stop(msg.url())
116
- end
117
+ flow.on_input(action_id, action)
117
118
end
0 commit comments