You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request introduces several new features and improvements to the Backbone scripting system, focusing on enhancing script lifecycle management, HTTP request handling, and JSON construction. It also refactors event handling for inter-script communication and simplifies command, item, and entity registration. The documentation (README.md) has been updated to reflect these changes and provide new usage examples.
Key changes include:
1. HTTP Request Utilities and Documentation
Added new utility functions (request, requestSync, and requestAndThen) for making HTTP requests from scripts, including both synchronous and asynchronous variants. These utilities are now documented in the README.md with usage examples.
2. Script Lifecycle and Registration DSL Improvements
Extracted the LifecycleBuilder and lifecycle DSL entrypoint into a dedicated file, improving modularity and clarity.
Added new DSL functions: useCommand, useItem, and useEntity for simplified registration and unregistration of commands, items, and entities in script lifecycles.
Updated the documentation to demonstrate the new registration DSL and improved lifecycle examples.
3. Inter-Script Communication Refactor
Renamed InterScriptDuckTypedEvent to IscEvent and moved it to a new package for clarity and consistency. Updated all usages accordingly.
Renamed the DSL function from interScript to interScriptListener to better reflect its purpose and updated the documentation.
4. JSON Builder Utility
Introduced a new JsonBuilder utility and DSL for constructing JSON objects and arrays in scripts, along with helper functions jsonTree and json.
5. Minor Documentation and Logging Updates
Improved logging in lifecycle hooks for better debugging.
Minor documentation and formatting updates in README.md, including placeholder section cleanup.
These changes collectively make scripting with Backbone more powerful, modular, and user-friendly.
Copy file name to clipboardExpand all lines: README.md
+38-20Lines changed: 38 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,11 +90,11 @@ lifecycle {
90
90
var otherCounter =0
91
91
92
92
onLoad {
93
-
Backbone.registerListener(this)
93
+
println("Script loaded! Counter: $counter | Other Counter: $otherCounter")
94
94
}
95
95
96
96
onUnload {
97
-
Backbone.unregisterListener(this)
97
+
println("Script unloaded! Counter: $counter | Other Counter: $otherCounter")
98
98
}
99
99
100
100
// This event fires every server tick while the script is enabled.
@@ -279,7 +279,7 @@ Use `interScript` to listen for messages with a specific id. The handler receive
279
279
280
280
```kotlin
281
281
lifecycle {
282
-
interScript("abc") { map ->
282
+
interScriptListener("abc") { map ->
283
283
val abc = map.pull<String>("abc")
284
284
println("Received inter-script message: $abc")
285
285
}
@@ -291,6 +291,34 @@ lifecycle {
291
291
- The data is passed as an immutable `IscMap`, which supports type-safe retrieval with `pull<T>(key)`.
292
292
- This system is ideal for modular scripts, cross-script events, and decoupled communication.
293
293
294
+
### HTTP Requests in Scripts
295
+
296
+
Backbone scripts can easily make HTTP requests and handle responses using the built-in DSL. This is useful for integrating with web APIs, fetching data, or interacting with external services directly from your scripts.
297
+
298
+
#### Example: Making an HTTP Request in a Script
299
+
300
+
You can use the `requestAndThen` function inside your script's lifecycle to perform HTTP requests asynchronously. The response is provided to a callback, where you can process the result and interact with the server.
0 commit comments