|
15 | 15 |
|
16 | 16 | class ExampleEditorDebugger extends EditorDebuggerPlugin: |
17 | 17 |
|
18 | | - func _has_capture(prefix): |
19 | | - # Return true if you wish to handle message with this prefix. |
20 | | - return prefix == "my_plugin" |
| 18 | + func _has_capture(capture): |
| 19 | + # Return true if you wish to handle messages with the prefix "my_plugin:". |
| 20 | + return capture == "my_plugin" |
21 | 21 |
|
22 | 22 | func _capture(message, data, session_id): |
23 | 23 | if message == "my_plugin:ping": |
24 | 24 | get_session(session_id).send_message("my_plugin:echo", data) |
| 25 | + return true |
| 26 | + return false |
25 | 27 |
|
26 | 28 | func _setup_session(session_id): |
27 | 29 | # Add a new tab in the debugger session UI containing a label. |
28 | 30 | var label = Label.new() |
29 | | - label.name = "Example plugin" |
| 31 | + label.name = "Example plugin" # Will be used as the tab title. |
30 | 32 | label.text = "Example plugin" |
31 | 33 | var session = get_session(session_id) |
32 | 34 | # Listens to the session started and stopped signals. |
|
43 | 45 | remove_debugger_plugin(debugger) |
44 | 46 | [/gdscript] |
45 | 47 | [/codeblocks] |
| 48 | + To connect on the running game side, use the [EngineDebugger] singleton: |
| 49 | + [codeblocks] |
| 50 | + [gdscript] |
| 51 | + extends Node |
| 52 | + |
| 53 | + func _ready(): |
| 54 | + EngineDebugger.register_message_capture("my_plugin", _capture) |
| 55 | + EngineDebugger.send_message("my_plugin:ping", ["test"]) |
| 56 | + |
| 57 | + func _capture(message, data): |
| 58 | + # Note that the "my_plugin:" prefix is not used here. |
| 59 | + if message == "echo": |
| 60 | + prints("Echo received:", data) |
| 61 | + return true |
| 62 | + return false |
| 63 | + [/gdscript] |
| 64 | + [/codeblocks] |
| 65 | + [b]Note:[/b] While the game is running, [method @GlobalScope.print] and similar functions [i]called in the editor[/i] do not print anything, the Output Log prints only game messages. |
46 | 66 | </description> |
47 | 67 | <tutorials> |
48 | 68 | </tutorials> |
|
68 | 88 | <param index="1" name="data" type="Array" /> |
69 | 89 | <param index="2" name="session_id" type="int" /> |
70 | 90 | <description> |
71 | | - Override this method to process incoming messages. The [param session_id] is the ID of the [EditorDebuggerSession] that received the message (which you can retrieve via [method get_session]). |
| 91 | + Override this method to process incoming messages. The [param session_id] is the ID of the [EditorDebuggerSession] that received the [param message]. Use [method get_session] to retrieve the session. This method should return [code]true[/code] if the message is recognized. |
72 | 92 | </description> |
73 | 93 | </method> |
74 | 94 | <method name="_goto_script_line" qualifiers="virtual"> |
|
90 | 110 | <return type="void" /> |
91 | 111 | <param index="0" name="session_id" type="int" /> |
92 | 112 | <description> |
93 | | - Override this method to be notified whenever a new [EditorDebuggerSession] is created (the session may be inactive during this stage). |
| 113 | + Override this method to be notified whenever a new [EditorDebuggerSession] is created. Note that the session may be inactive during this stage. |
94 | 114 | </description> |
95 | 115 | </method> |
96 | 116 | <method name="get_session"> |
|
0 commit comments