### Debugger server startup output
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/zerobrane.md
Example output shown when the debugging server starts and a debugging session begins. It indicates the server address and the mapped project directory.
```txt
Debugger server started at localhost:8172.
Mapped remote request for '/' to '/Users/my_user/Documents/Projects/Defold_project/'.
Debugging session started in '/Users/my_user/Documents/Projects/Defold_project'.
```
--------------------------------
### .defignore example
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/project-defignore.md
Lists files and folders to exclude in the .defignore file. Each line must start with a '/' and is matched case-sensitively against project paths relative to the project root.
```text
/path/to/file.png
/otherpath
```
--------------------------------
### Manage iOS simulators with xcrun simctl
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/ios.md
Use these commands to manage iOS simulators from the command line. The list command shows available devices, boot starts a named simulator, install places an app on the booted simulator, and open launches the Simulator app.
```bash
# show a list of available devices
xcrun simctl list
# boot an iPhone X simulator
xcrun simctl boot "iPhone X"
# install your.app to a booted simulator
xcrun simctl install booted your.app
# launch the simulator
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
```
--------------------------------
### Runtime material manipulation with go.get() and go.set()
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/gui.md
Shows how to get and set the material assigned to a GUI node using go.get() and go.set() with the 'materials' property and a key. The example uses a resource property to hold the new material and prints the current material file paths.
```lua
go.property("myeffect", resource.material("/assets/myeffect.material"))
function init(self)
-- get the material file currently assigned to the material with id 'effect'
print(go.get("#gui", "materials", { key = "effect" })) -- /effect.material
-- set the material id 'effect' to the material file assigned to the resource property 'myeffect'
go.set("#gui", "materials", self.myeffect, { key = "effect" })
-- get the new material file assigned to the material with id 'effect'
print(go.get("#gui", "materials", { key = "effect" })) -- /assets/myeffect.material
end
```
--------------------------------
### Android base manifest example
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/extensions-manifest-merge-tool.md
Base manifest used as the starting point for merging. It includes package, version, install location, features, SDK versions, application label, and a permission.
```xml
```
--------------------------------
### init-Funktion: GUI-Knoten abrufen und Setup starten
Source: https://github.com/defold/doc/blob/master/docs/de/tutorials/level-complete.md
Initialisiert die GUI-Knoten für Überschrift, Sterne, Punktzahl und Impressum. Speichert die Start- und Endfarbe der Punktzahl und ruft die setup-Funktion auf.
```Lua
function init(self)
-- retrieve nodes for easier access
self.heading = gui.get_node("heading")
self.stars = {gui.get_node("star_left"), gui.get_node("star_mid"), gui.get_node("star_right")}
self.score = gui.get_node("score")
self.imprint = gui.get_node("imprint")
-- start color of the score
self.score_start_color = vmath.vector4(1, 1, 1, 1)
-- save score color and animate towards it during counting later
self.score_end_color = gui.get_color(self.score)
setup(self)
end
```
--------------------------------
### Get query parameters as Lua table
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/html5.md
Full helper function to get all query parameters as a Lua table. Returns an empty table if no query string is present. Example usage in init() prints the value of foo1.
```lua
local function get_query_parameters()
local url = html5.run("window.location")
-- get the query part of the url (the bit after ?)
local query = url:match(".*?(.*)")
if not query then
return {}
end
local params = {}
-- iterate over all key value pairs
for kvp in query:gmatch("([^&]+)") do
local key, value = kvp:match("(.+)=(.+)")
params[key] = value
end
return params
end
function init(self)
local params = get_query_parameters()
print(params.foo1) -- bar1
end
```
--------------------------------
### Create box and text nodes from scratch with gui.new_box_node and gui.new_text_node
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/gui-script.md
Shows how to create a box node and a text node at runtime using gui.new_box_node() and gui.new_text_node(). The returned references are used to set color and font. The example sets a new position and size for the box node.
```lua
-- Create a new box node
local new_position = vmath.vector3(400, 300, 0)
local new_size = vmath.vector3(450, 400, 0)
local new_boxnode = gui.new_box_node(new_position, new_size)
gui.set_color(new_boxnode, vmath.vector4(0.2, 0.26, 0.32, 1))
-- Create a new text node
local new_textnode = gui.new_text_node(new_position, "Hello!")
gui.set_font(new_textnode, "sourcesans")
gui.set_color(new_textnode, vmath.vector4(0.69, 0.6, 0.8, 1.0))
```
--------------------------------
### Get and set preferences with editor.prefs
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/editor-scripts.md
Shows how to read and write preferences after the schema is registered. The get function returns a single value or a table for a group, and set can update multiple nested preferences at once. The example uses the 'my_json_formatter' script's preferences.
```lua
-- Get a specific preference
editor.prefs.get("my_json_formatter.indent.type")
-- Returns: "spaces"
-- Get an entire preference group
editor.prefs.get("my_json_formatter")
-- Returns:
-- {
-- jq_path = "",
-- indent = {
-- size = 2,
-- type = "spaces"
-- }
-- }
-- Set multiple nested preferences at once
editor.prefs.set("my_json_formatter.indent", {
type = "tabs",
size = 1
})
```
--------------------------------
### Get position of a game object in a collection (Lua)
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/building-blocks.md
Use this snippet to get the position of a game object that is inside a sub-collection. The path 'bean/bean' refers to the game object with id 'bean' inside the collection with id 'bean'. This example is from the file 'can.script'.
```lua
-- file: can.script
-- get position of the "bean" game object in the "bean" collection
local pos = go.get_position("bean/bean")
```
--------------------------------
### init() function for render script setup
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/render.md
Sets up render predicates for tile, gui, text, particle, and model, creates cameras for world and GUI projections, and initializes the state. This is the first part of the custom render script.
```lua
function init(self)
-- Define the render predicates. Each predicate is drawn by itself and
-- that allows us to change the state of OpenGL between the draws.
self.predicates = create_predicates("tile", "gui", "text", "particle", "model")
-- Create and fill data tables will be used in update()
local state = create_state()
self.state = state
local camera_world = create_camera(state, "camera_world", true)
init_camera(camera_world, get_stretch_projection)
local camera_gui = create_camera(state, "camera_gui")
init_camera(camera_gui, get_gui_projection)
update_state(state)
end
```
--------------------------------
### Debug iOS game with ios-deploy
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/debugging-game-and-system-logs.md
Install and debug an iOS game on a device using ios-deploy. The game must be signed with a provisioning profile that includes the device, and bundling is only available on macOS. This command installs the app, starts it, and attaches an LLDB debugger.
```txt
$ ios-deploy --debug --bundle # NOTE: not the .ipa file
```
--------------------------------
### Invoke bob.jar with --help to show usage
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/bob.md
Run Bob from the command line with the --help flag to display its usage and all available options. The output shows the full list of command-line options, including deprecated flags like --certificate and --debug, and defaults such as --archive-resource-padding (default 4) and --binary-output (default "//").
```text
$ java -jar bob.jar --help
usage: bob [options] [commands]
-a,--archive Build archive
-ar,--architectures Comma separated list of
architectures to include for the
platform
--archive-resource-padding The alignment of the resources in
the game archive. Default is 4
-bf,--bundle-format Which formats to create the
application bundle in. Comma
separated list. (Android: 'apk'
and 'aab')
--binary-output Location where built engine
binary will be placed. Default is
"//"
-bo,--bundle-output Bundle output directory
-br,--build-report DEPRECATED! Use
--build-report-json instead
-brhtml,--build-report-html Filepath where to save a build
report as HTML
-brjson,--build-report-json Filepath where to save a build
report as JSON
--build-artifacts If left out, will default to
build the engine. Choices:
'engine', 'plugins', 'library'.
Comma separated list
--build-input Project resource path to build
instead of game.project. May be
specified more than once. More
than one occurrence is allowed
--build-input-file File containing project resource
paths to build instead of
game.project. May be specified
more than once. More than one
occurrence is allowed
--build-server The build server (when using
native extensions)
--build-server-header Additional build server header to
set. More than one occurrence is
allowed
-ce,--certificate DEPRECATED! Use --keystore
instead
-d,--debug DEPRECATED! Use --variant=debug
instead
--debug-ne-upload Outputs the files sent to build
server as upload.zip
--debug-output-glsl Force build GLSL shaders
--debug-output-hlsl Force build HLSL shaders
--debug-output-msl Force build Metal shaders
--debug-output-spirv Force build SPIR-V shaders
--debug-output-wgsl Force build WGSL shaders
--defoldsdk What version of the defold sdk
(sha1) to use
-e,--email User email
-ea,--exclude-archive Exclude resource archives from
application bundle. Use this to
```
--------------------------------
### on_bundle_started(opts)
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/editor-scripts.md
Lifecycle hook executed when a bundle or HTML5 build starts.
```APIDOC
## on_bundle_started(opts)
### Description
Executed when you create a bundle or build the HTML5 version of a game. Changes triggered by this hook will appear in the bundle, and errors will abort the bundle.
### Method
Lifecycle Hook
### Parameters
#### opts (table) - Required
- **output_directory** (string) - A file path pointing to the directory with the bundle output. For example, `"/path/to/project/build/default_html5/__htmlLaunchDir"` for the Project ▸ Build HTML5 option.
- **platform** (string) - The platform the game is bundled for. See the list of possible platform values in the Bob manual.
- **variant** (string) - The bundle variant: `"debug"`, `"release"`, or `"headless"`.
### Example
```lua
function M.on_bundle_started(opts)
print("Bundling for platform: " .. opts.platform)
end
```
```
--------------------------------
### board.script init() - remove temporary board setup
Source: https://github.com/defold/doc/blob/master/docs/en/tutorials/magic-link.md
The init() function in board.script currently contains the board structure and block lists. The tutorial instructs to remove the temporary board setup call from this function, as the main menu script will handle starting the game.
```lua
-- board.script
--
-- INIT
--
function init(self)
self.board = {} -- Contains the board structure
self.blocks = {} -- List of all blocks. Used for easy filtering on selection.
self.chain = {} -- Current selection chain
self.connectors = {} -- Connector elements to mark the selection chain
self.num_magic = 3 -- Number of magic blocks on the board
self.drops = 1 -- Number of drops you have available
self.magic_blocks = {} -- Magic blocks that are lined up
self.dragging = false -- Drag touch input
end
```
--------------------------------
### Start local HTTP server with Python 3
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/html5.md
Starts a local HTTP server for Python 3 to test the HTML5 bundle. Run this command in the bundle folder.
```sh
python -m http.server
```
--------------------------------
### Get help
Source: https://github.com/defold/doc/blob/master/scripts/README.md
Displays the command-line help for the script, listing all available options and usage information.
```bash
python docs_consistency_checker.py --help
```
--------------------------------
### Start local HTTP server with python3
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/html5.md
Alternative command to start a local HTTP server for Python 3 to test the HTML5 bundle. Run this command in the bundle folder.
```sh
python3 -m http.server
```
--------------------------------
### Switch orthographic mode at runtime
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/camera.md
Switch between orthographic modes at runtime using camera.set_orthographic_mode(). The example shows how to get the current mode and switch to auto-fit, auto-cover, or fixed mode.
```lua
-- get current mode (one of camera.ORTHO_MODE_FIXED, _AUTO_FIT, _AUTO_COVER)
local mode = camera.get_orthographic_mode("#camera")
-- switch to auto-fit (contain) to always keep the full design area visible
camera.set_orthographic_mode("#camera", camera.ORTHO_MODE_AUTO_FIT)
-- switch to auto-cover to ensure the design area covers the window
camera.set_orthographic_mode("#camera", camera.ORTHO_MODE_AUTO_COVER)
-- switch to fixed mode to use orthographic_zoom without automatic sizing
camera.set_orthographic_mode("#camera", camera.ORTHO_MODE_FIXED)
```
--------------------------------
### Start local HTTP server with Python 2
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/html5.md
Starts a local HTTP server for Python 2 to test the HTML5 bundle. Run this command in the bundle folder.
```sh
python -m SimpleHTTPServer
```
--------------------------------
### Test drop mechanic (on_reload or input action)
Source: https://github.com/defold/doc/blob/master/docs/en/tutorials/magic-link.md
Snippet to test the drop mechanic, for example in on_reload() or tied to a temporary input action. It gets drop spots and performs the drop if any are available.
```lua
s = dropspots(self)
if #s > 0 then
-- Do the drop
drop(self, s)
end
```
--------------------------------
### Access raw gamepad input
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/input-gamepads.md
Use the `Raw` binding to get unfiltered button, axis, and hat input from any connected gamepad. This example prints the raw gamepad data using `pprint`.
```lua
function on_input(self, action_id, action)
if action_id == hash("raw") then
pprint(action.gamepad_buttons)
pprint(action.gamepad_axis)
pprint(action.gamepad_hats)
end
end
```
--------------------------------
### Level complete GUI script: setup and init and delete_small_star
Source: https://github.com/defold/doc/blob/master/docs/en/tutorials/level-complete.md
Defines the initial setup for a level complete GUI scene, retrieving nodes and setting initial values. The setup function is called from init and expected to be called from on_reload to reset state when the script is reloaded from the editor. The delete_small_star function removes a small star node after its animation has completed.
```lua
local function setup(self)
-- make heading color transparent
local c = gui.get_color(self.heading)
c.w = 0
gui.set_color(self.heading, c)
-- make heading shadow transparent
c = gui.get_shadow(self.heading)
c.w = 0
gui.set_shadow(self.heading, c)
-- set heading to twice the scale initially
local s = 2
gui.set_scale(self.heading, vmath.vector3(s, s, s))
-- set initial score (0)
gui.set_text(self.score, "0")
-- set score color to opaque white
gui.set_color(self.score, vmath.vector4(1, 1, 1, 1))
-- set scale so the score can grow while counting
gui.set_scale(self.score, vmath.vector4(score_start_scale, score_start_scale, 1, 0))
-- make all big stars transparent
for i=1,#self.stars do
gui.set_color(self.stars[i], vmath.vector4(1, 1, 1, 0))
end
-- make the imprint transparent
gui.set_color(self.imprint, vmath.vector4(1, 1, 1, 0))
-- the score currently being displayed
self.current_score = 0
-- the target score when counting
self.target_score = 0
end
```
```lua
function init(self)
-- retrieve nodes for easier access
self.heading = gui.get_node("heading")
self.stars = {gui.get_node("star_left"), gui.get_node("star_mid"), gui.get_node("star_right")}
self.score = gui.get_node("score")
self.imprint = gui.get_node("imprint")
-- start color of the score
self.score_start_color = vmath.vector4(1, 1, 1, 1)
-- save score color and animate towards it during counting later
self.score_end_color = gui.get_color(self.score)
setup(self)
end
```
```lua
-- delete a small star, called when the star has finished animating
local function delete_small_star(self, small_star)
gui.delete_node(small_star)
end
```
--------------------------------
### Get bone game object with model.get_go()
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/model-animation.md
Lua example that retrieves the game object id for a bone named 'Bone_002' in the 'wiggler' model. The returned id can be used to manipulate the bone as a game object.
```lua
-- Get the middle bone go of our wiggler model
local bone_go = model.get_go("#wiggler", "Bone_002")
-- Now do something useful with the game object...
```
--------------------------------
### Define custom HTTP server routes with get_http_server_routes
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/editor-scripts.md
Add this function to an editor script to extend the editor's HTTP server. It returns a list of route definitions. The example prints the server URL and defines a GET route that returns a simple text response.
```lua
print("My route: " .. http.server.url .. "/my-extension")
function M.get_http_server_routes()
return {
http.server.route("/my-extension", "GET", function(request)
return http.server.response(200, "Hello world!")
end)
}
end
```
--------------------------------
### ext.manifest example with platform contexts
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/extensions-ext-manifests.md
Example ext.manifest file for an AdExtension, defining platform-specific contexts for arm64-ios and arm64_sim-ios. If a platform is missing from the platforms list, the build still succeeds but without extra flags.
```yaml
name: "AdExtension"
platforms:
arm64-ios:
context:
frameworks: ["CoreGraphics", "CFNetwork", "GLKit", "CoreMotion", "MessageUI", "MediaPlayer", "StoreKit", "MobileCoreServices", "AdSupport", "AudioToolbox", "AVFoundation", "CoreGraphics", "CoreMedia", "CoreMotion", "CoreTelephony", "CoreVideo", "Foundation", "GLKit", "JavaScriptCore", "MediaPlayer", "MessageUI", "MobileCoreServices", "OpenGLES", "SafariServices", "StoreKit", "SystemConfiguration", "UIKit", "WebKit"]
flags: ["-stdlib=libc++"]
linkFlags: ["-ObjC"]
libs: ["z", "c++", "sqlite3"]
defines: ["MY_DEFINE"]
arm64_sim-ios:
context:
frameworks: ["CoreGraphics", "CFNetwork", "GLKit", "CoreMotion", "MessageUI", "MediaPlayer", "StoreKit", "MobileCoreServices", "AdSupport", "AudioToolbox", "AVFoundation", "CoreGraphics", "CoreMedia", "CoreMotion", "CoreTelephony", "CoreVideo", "Foundation", "GLKit", "JavaScriptCore", "MediaPlayer", "MessageUI", "MobileCoreServices", "OpenGLES", "SafariServices", "StoreKit", "SystemConfiguration", "UIKit", "WebKit"]
flags: ["-stdlib=libc++"]
linkFlags: ["-ObjC"]
libs: ["z", "c++", "sqlite3"]
defines: ["MY_DEFINE"]
```
--------------------------------
### Defold address syntax examples
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/addressing.md
Shows various ways to construct addresses in Defold: relative component references with '#', game object references, absolute paths, and shorthand for current object. The examples illustrate the syntax used in API calls like factory.create, go.set, go.get_position, go.set_position, msg.post, and go.get_id.
```lua
local id = factory.create("#enemy_factory")
go.set("my_gameobject#my_label", "text", "Hello World!")
local pos = go.get_position("my_gameobject")
go.set_position(pos, "/level/stuff/other_gameobject")
msg.post("#", "hello_there")
local id = go.get_id(".")
```
--------------------------------
### Start Extender Server with Docker Compose
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/extender-local-setup.md
Starts the Extender build server with the specified profile. Replace with one of: all, android, web, linux, windows, consoles, nintendo, playstation, or metrics. After startup, use http://localhost:9000 as the Build server address.
```sh
docker compose -p extender -f server/docker/docker-compose.yml --profile up
```
--------------------------------
### Runtime font manipulation with go.get() and go.set()
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/gui.md
Shows how to get and set the font assigned to a GUI node using go.get() and go.set() with the 'fonts' property and a key. The example uses a resource property to hold the new font and prints the current font file paths.
```lua
go.property("mybigfont", resource.font("/assets/mybig.font"))
function init(self)
-- get the font file currently assigned to the font with id 'default'
print(go.get("#gui", "fonts", { key = "default" })) -- /builtins/fonts/default.font
-- set the font with id 'default' to the font file assigned to the resource property 'mybigfont'
go.set("#gui", "fonts", self.mybigfont, { key = "default" })
-- get the new font file assigned to the font with id 'default'
print(go.get("#gui", "fonts", { key = "default" })) -- /assets/mybig.font
end
```
--------------------------------
### on_build_started(opts)
Source: https://github.com/defold/doc/blob/master/docs/en/manuals/editor-scripts.md
Lifecycle hook executed when a build starts.
```APIDOC
## on_build_started(opts)
### Description
Executed when the game is built to run locally or on a remote target using either the Project Build or Debug Start options. Changes made in this hook will appear in the built game. Raising an error from this hook will abort the build.
### Method
Lifecycle Hook
### Parameters
#### opts (table) - Required
- **platform** (string) - The platform the game is built for, in `%arch%-%os%` format. Currently always the same value as in `editor.platform`.
### Example
```lua
function M.on_build_started(opts)
local file = io.open("assets/build.json", "w")
file:write('{"build_time": "' .. os.date() .. '"}')
file:close()
end
```
```