### Instant App Logic Example Source: https://github.com/defold/defold.github.io/blob/master/extension-googleplayinstant/index.md Example demonstrating how to handle instant app specific logic, such as saving data and showing an install prompt, using 'instantapp.is_instant_app()', 'instantapp.get_cookie_max_size()', 'instantapp.set_cookie()', and 'instantapp.show_install_prompt()'. ```lua if instantapp and instantapp.is_instant_app() then -- if this is instant app save data for the main app and show install prompt local cookie_size = instantapp.get_cookie_max_size() if cookie_size > 0 then instantapp.set_cookie(bytes_of_save_data) end instantapp.show_install_prompt() else -- regular app logic end ``` -------------------------------- ### Initialize and Start Game (JavaScript) Source: https://github.com/defold/defold.github.io/blob/master/extension-fbinstant/index.md Example of initializing the FBInstant API and starting the game asynchronously using JavaScript Promises. ```javascript FBInstant.initializeAsync().then(function() { FBInstant.startGameAsync().then(function() { var playerID = FBInstant.player.getID(); var playerName = FBInstant.player.getName(); }); }); ``` -------------------------------- ### Install libopenal1 for Game Launch Source: https://github.com/defold/defold.github.io/blob/master/_includes/shared/en/linux-faq.md Install the 'libopenal1' package (or equivalent like 'libopenal-dev') if your Defold game fails to start with a 'libopenal.so.1' not found error. ```bash $ apt-get install libopenal-dev ``` -------------------------------- ### Load Engine and Example Source: https://github.com/defold/defold.github.io/blob/master/_layouts/example.html Initializes the Defold engine by loading specified modules. Use this at the start of your application to set up the engine environment. ```javascript EngineLoader.load("canvas", "Defoldexamples"); ``` -------------------------------- ### Show Install Prompt for Instant App Source: https://github.com/defold/defold.github.io/blob/master/extension-googleplayinstant/index.md Call 'instantapp.show_install_prompt()' when the app is an instant app to prompt the user to install the full application. ```lua if instantapp.is_instant_app() then instantapp.show_install_prompt() -- if this is instant app then show install prompt else -- regular app logic end ``` -------------------------------- ### Example: on_build_started Lifecycle Hook Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/editor-scripts.md This hook is executed when a game build starts. It can be used to perform actions like creating a build information file. Errors in this hook will abort the build. ```lua local M = {} function M.on_build_started(opts) local file = io.open("assets/build.json", "w") file:write('{"build_time": "' .. os.date() .. '"}') file:close() end return M ``` -------------------------------- ### Showing the Install Prompt Source: https://github.com/defold/defold.github.io/blob/master/extension-googleplayinstant/index.md This function displays a dialog that allows the user to install the current instant app. It should be called within a check for `instantapp.is_instant_app()`. ```APIDOC ## instantapp.show_install_prompt() ### Description Shows a dialog that allows the user to install the current instant app. ### Method instantapp.show_install_prompt() ### Example ```lua if instantapp and instantapp.is_instant_app() then instantapp.show_install_prompt() -- if this is instant app then show install prompt else -- regular app logic end ``` ``` -------------------------------- ### Install Google Instant Apps Tools Source: https://github.com/defold/defold.github.io/blob/master/extension-googleplayinstant/index.md Command to install the 'extra-google-instantapps' tools using the sdkmanager. ```bash ./android-sdk/cmdline-tools/latest/bin/sdkmanager --verbose "extras;google;instantapps" ``` -------------------------------- ### Bundle Resources Configuration Example Source: https://github.com/defold/defold.github.io/blob/master/_includes/shared/uk/bundle-resources.md Example of how to configure the 'Bundle Resources' field in game.project to include platform-specific and common resource files. ```plaintext res ``` -------------------------------- ### Defold Addressing Examples Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/addressing.md Demonstrates various ways to use Defold's addressing mechanism to create, manipulate, and get information about game objects and components. ```lua local id = factory.create("#enemy_factory") label.set_text("my_gameobject#my_label", "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(".") ``` -------------------------------- ### Get and Set Tile Example in Lua Source: https://github.com/defold/defold.github.io/blob/master/llms/examples/tilemap/get_set_tile.md This script handles input to set tiles on a click and display information about the tile under the mouse cursor. It requires a tilemap component with the ID '#level' and a label component with the ID '#label'. ```lua local TILE_SIZE = 64 -- helper function check if a tile coordinate is within the bounds of the tilemap local function within_bounds(x, y) local bx, by, bw, bh = tilemap.get_bounds("#level") return x >= bx and y >= by and x < (bx + bw) and y < (by + bh) end function init(self) msg.post(".", "acquire_input_focus") end function on_input(self, action_id, action) local tile_x = math.ceil(action.x / TILE_SIZE) local tile_y = math.ceil(action.y / TILE_SIZE) if within_bounds(tile_x, tile_y) then -- click to place a flower if action_id == hash("touch") and action.pressed then tilemap.set_tile("#level", "layer1", tile_x, tile_y, 77) end -- show tile info local tile = tilemap.get_tile("#level", "layer1", tile_x, tile_y) local text = ("x: %d y: %d tile: %d"):format(tile_x, tile_y, tile) label.set_text("#label", text) else local text = ("x: %d y: %d out of bounds"):format(tile_x, tile_y) label.set_text("#label", text) end end ``` -------------------------------- ### Start engine with config override Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/sys-lua.md Override bootstrap and custom configuration values when starting the Defold engine from the command line. ```bash $ dmengine --config=bootstrap.main_collection=/mytest.collectionc --config=mygame.testmode=1 ``` -------------------------------- ### Install libffi.so.7 for Defold Source: https://github.com/defold/defold.github.io/blob/master/llms-manuals.txt Use these commands to download and install libffi.so.7 if your distribution's version is incompatible with Defold, which can cause crashes. ```bash $ wget http://ftp.br.debian.org/debian/pool/main/libf/libffi/libffi7_3.3-6_amd64.deb $ sudo dpkg -i libffi7_3.3-6_amd64.deb ``` -------------------------------- ### Start Python 2 HTTP Server Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/html5.md Use this command to start a simple HTTP server for testing HTML5 builds in Python 2. ```sh python -m SimpleHTTPServer ``` -------------------------------- ### Start Python 3 HTTP Server Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/html5.md Use this command to start a simple HTTP server for testing HTML5 builds in Python 3. ```sh python -m http.server ``` -------------------------------- ### Android Base Manifest Example Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/extensions-manifest-merge-tool.md An example of a base AndroidManifest.xml file. This serves as the starting point for the manifest merging process. ```xml ``` -------------------------------- ### Complete Connection Example Source: https://github.com/defold/defold.github.io/blob/master/extension-photon-fusion/connection.md A full script demonstrating connection to Photon Cloud, joining a room with custom options, and printing a confirmation message. ```lua fusion.init_from_settings() fusion.on_event(function(self, event_id, data) if event_id == fusion.EVENT_CONNECTED then local options = { max_players = 8, is_visible = true, custom_properties = { map = "arena" }, lobby_properties = { "map" } } fusion.join_or_create_room("lobby", options) elseif event_id == fusion.EVENT_ROOM_JOINED then print("joined room:", data.name) end end) fusion.connect() ``` -------------------------------- ### Get Camera Frame Source: https://github.com/defold/defold.github.io/blob/master/llms-apis.txt Captures the current frame from the camera session. This should be called after the camera has started and potentially after getting info. ```Lua self.cameraframe = camera.get_frame() ``` -------------------------------- ### Example Source: https://github.com/defold/defold.github.io/blob/master/extension-photon-fusion/connection.md A complete script demonstrating connection, room joining with custom options, and event handling. ```APIDOC ## Example A complete script that connects to Photon Cloud, joins a room with custom options and prints when the player enters. ```lua fusion.init_from_settings() fusion.on_event(function(self, event_id, data) if event_id == fusion.EVENT_CONNECTED then local options = { max_players = 8, is_visible = true, custom_properties = { map = "arena" }, lobby_properties = { "map" } } fusion.join_or_create_room("lobby", options) elseif event_id == fusion.EVENT_ROOM_JOINED then print("joined room:", data.name) end end) fusion.connect() ``` ``` -------------------------------- ### instantapp.show_install_prompt Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/extension-googleplayinstant_instantapp.md Shows a dialog that allows the user to install the current instant app. ```APIDOC ## instantapp.show_install_prompt ### Description Shows a dialog that allows the user to install the current instant app. ### Type FUNCTION ``` -------------------------------- ### GetInstalledAdapterFamily Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/engine-graphics-src-dmsdk-graphics-graphics-h.md Get the installed graphics adapter family. ```APIDOC ## GetInstalledAdapterFamily ### Description Get installed graphics adapter family ### Returns - `family` (dmGraphics::AdapterFamily) - Installed adapter family ``` -------------------------------- ### Install Bundler and Project Dependencies Source: https://github.com/defold/defold.github.io/blob/master/README.md Installs bundler, sets the local bundle path to 'vendor/bundle', and then installs all project gem dependencies. This is a common setup step for Ruby projects managed with Bundler. ```sh gem install bundler bundle config set --local path 'vendor/bundle' bundle install ``` -------------------------------- ### Initialize and Setup GUI Nodes Source: https://github.com/defold/defold.github.io/blob/master/tutorials/level-complete.md Initializes GUI nodes and sets their initial states in the `init` and `setup` functions. This includes making text elements transparent, setting initial scales, and preparing score and star nodes for animation. ```lua -- file: level_complete.gui_script -- how fast the score is incremented per second local score_inc_speed = 51100 -- how long time between each update of the score local dt = 0.03 -- scale of the score at the start of counting local score_start_scale = 0.7 -- scale of the score when the target score has been reached local score_end_scale = 1.0 -- how much the score "bounces" at each increment local score_bounce_factor = 1.1 -- how many small stars to spawn for each big star local small_star_count = 16 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 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 -- 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 -- animate a small star according to the given initial position and angle local function animate_small_star(self, pos, angle) -- direction of travel for the small star local dir = vmath.vector3(math.cos(angle), math.sin(angle), 0, 0) -- create a small star local small_star = gui.new_box_node(pos + dir * 20, vmath.vector3(64, 64, 0)) ``` -------------------------------- ### Install libopenal1 for Linux Source: https://github.com/defold/defold.github.io/blob/master/llms-manuals.txt Install the libopenal1 package if Defold fails to start on Linux with an error message about missing libopenal.so.1. The package name may vary by distribution. ```bash $ apt-get install libopenal-dev ``` -------------------------------- ### Lua Callback Invocation Example Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/engine-script-src-dmsdk-script-script-h.md This example demonstrates how to create, invoke, and destroy a Lua callback. It includes setup, parameter pushing, calling the Lua function, and teardown. ```c dmScript::LuaCallbackInfo* g_MyCallbackInfo = 0; static void InvokeCallback(dmScript::LuaCallbackInfo* cbk) { if (!dmScript::IsCallbackValid(cbk)) return; lua_State* L = dmScript::GetCallbackLuaContext(cbk); DM_LUA_STACK_CHECK(L, 0) if (!dmScript::SetupCallback(cbk)) { dmLogError("Failed to setup callback"); return; } lua_pushstring(L, "Hello from extension!"); lua_pushnumber(L, 76); dmScript::PCall(L, 3, 0); // instance + 2 dmScript::TeardownCallback(cbk); } static int Start(lua_State* L) { DM_LUA_STACK_CHECK(L, 0); g_MyCallbackInfo = dmScript::CreateCallback(L, 1); return 0; } static int Update(lua_State* L) { DM_LUA_STACK_CHECK(L, 0); static int count = 0; if( count++ == 5 ) { InvokeCallback(g_MyCallbackInfo); if (g_MyCallbackInfo) dmScript::DestroyCallback(g_MyCallbackInfo); g_MyCallbackInfo = 0; } return 0; } ``` -------------------------------- ### Get Game Object Position (Lua Extension) Source: https://github.com/defold/defold.github.io/blob/master/llms-apis.txt Example of how to get the position of a game object in a script extension using C++ and Lua. Requires DM_LUA_STACK_CHECK for stack validation. ```cpp static int get_position(lua_State* L) { DM_LUA_STACK_CHECK(L, 3); dmGameObject::HInstance instance = dmScript::CheckGOInstance(L, 1); dmVMath::Point3 position = dmGameObject::GetPosition(instance); lua_pushnumber(L, position.getX()); lua_pushnumber(L, position.getY()); lua_pushnumber(L, position.getZ()); return 3; } ``` -------------------------------- ### Example: on_build_started Lifecycle Hook Source: https://github.com/defold/defold.github.io/blob/master/manuals/editor-scripts.md This example demonstrates how to use the `on_build_started` hook to create a JSON file with the current build time. This hook is executed when the game is built for local or remote execution. Errors in this hook will abort the build. ```lua local M = {} function M.on_build_started(opts) local file = io.open("assets/build.json", "w") file:write('{"build_time": "' .. os.date() .. '"}') file:close() end return M ``` -------------------------------- ### Get and Set GUI Material Constants Source: https://github.com/defold/defold.github.io/blob/master/_posts/2024-07-22-Defold-1-9-1.md Access and modify material constants for GUI nodes using `gui.get` and `gui.set`. This example demonstrates how to get the 'tint' constant and animate its 'x' component. ```lua local node = gui.get_node("box") local tint = gui.get(node, "tint") tint.x = tint.x + dt * 0.1 go.set(node, "tint", tint) ``` -------------------------------- ### InstallAdapter Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/engine-graphics-src-dmsdk-graphics-graphics-h.md Installs a graphics adapter, initializing the specified graphics backend. This must be called before creating any graphics context. ```APIDOC ## InstallAdapter ### Description Installs a graphics adapter. Initializes the specified graphics backend (OpenGL, Vulkan, etc.). This must be called before creating any graphics context. ### Parameters - `family` (dmGraphics::AdapterFamily) - Graphics adapter family to install ### Returns - `success` (bool) - True if the adapter was successfully installed, false otherwise ``` -------------------------------- ### Get and Set Sprite Slice9 Values in Lua Source: https://github.com/defold/defold.github.io/blob/master/_posts/2024-04-29-Defold-1-8-0.md Use these Lua examples to get and set the slice9 parameters for a sprite component. The 'slice' property accepts a vector4, while individual components like 'slice.x' can also be modified. ```lua local values = go.get("#sprite", "slice") local value = go.get("#sprite", "slice.x") go.set("#sprite", "slice", vmath.vector4(1,2,3,4)) go.set("#sprite", "slice.x", 1337) ``` ```lua go.animate("#sprite", "slice", go.PLAYBACK_LOOP_PINGPONG, vmath.vector4(96, 96, 96, 96), go.EASING_INCUBIC, 2) go.animate("#sprite", "slice.x", go.PLAYBACK_LOOP_PINGPONG, 96, go.EASING_INCUBIC, 1) ``` -------------------------------- ### Initialize Render Script Source: https://github.com/defold/defold.github.io/blob/master/_includes/examples/render/post_processing/postprocess_render_script.md Sets up the render script by creating predicates, initializing the post-processing render target, and setting up cameras and state. ```lua function init(self) -- create the postprocess predicate and all of the default predicates self.predicates = create_predicates("postprocess", "tile", "gui", "particle", "model", "debug_text") -- default is stretch projection. copy from builtins and change for different projection -- or send a message to the render script to change projection: -- msg.post("@render:", "use_stretch_projection", { near = -1, far = 1 }) -- msg.post("@render:", "use_fixed_projection", { near = -1, far = 1, zoom = 2 }) -- msg.post("@render:", "use_fixed_fit_projection", { near = -1, far = 1 }) create_postprocess_rt(self, render.get_window_width(), render.get_window_height()) 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) -- Create a special camera that wraps camera components (if they exist) -- It will take precedence over any other camera, and not change from messages local camera_component = create_camera(state, "camera_component") update_state(state) end ``` -------------------------------- ### Basic Fragment Shader Source: https://github.com/defold/defold.github.io/blob/master/_includes/examples/mesh/triangle/mesh_fp.md This shader takes an input color and outputs it directly. It's a minimal example often used as a starting point. ```glsl #version 140 in mediump vec4 var_color; out vec4 out_fragColor; void main() { out_fragColor = var_color; } ``` -------------------------------- ### fusion.init_from_settings Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/extension-photon-fusion_fusion.md Initializes the Photon Fusion system using settings defined in the game.project file. ```APIDOC ## fusion.init_from_settings ### Description Initialize Fusion from game.project settings. ``` -------------------------------- ### Initialize and Use dmArray Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/engine-dlib-src-dmsdk-dlib-array-h.md Demonstrates basic initialization, capacity setting, pushing elements, and accessing elements by index. ```cpp dmArray a; a.SetCapacity(1); a.Push(1); int b = a[0]; ``` -------------------------------- ### Manipulating GUI nodes by ID Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/gui-script.md This example demonstrates how to get a reference to a GUI node using its ID, retrieve its current size, modify it, and then set the new size. ```lua -- extend the health bar by 10 units local healthbar_node = gui.get_node("healthbar") local size = gui.get_size(healthbar_node) size.x = size.x + 10 gui.set_size(healthbar_node, size) ``` -------------------------------- ### Defold Extension Folder Structure Example Source: https://github.com/defold/defold.github.io/blob/master/llms-full.txt Illustrates a common and recommended folder structure for Defold extensions, including directories for input, main project, extension source, libraries, resources, and build configurations. ```plaintext /root /input /main -- All the files for the actual example project /... /myextension -- The actual root folder of the extension ext.manifest /include -- External includes, used by other extensions /libs / -- External libraries for all supported platforms /src myextension.cpp -- The extension Lua api and the extension life cycle functions Also contains generic implementations of your Lua api functions. myextension_private.h -- Your internal api that each platform will implement (I.e. `myextension_Init` etc) myextension.mm -- If native calls are needed for iOS/macOS. Implements `myextension_Init` etc for iOS/macOS myextension_android.cpp -- If JNI calls are needed for Android. Implements `myextension_Init` etc for Android /java / -- Any java files needed for Android /res -- Any resources needed for a platform /external README.md -- Notes/scripts on how to build or package any external libraries /bundleres -- Resources that should be bundles for (see game.project and the [bundle_resources setting]([physics scale setting](#manuals:project-settings)) / game.project game.appmanifest -- Any extra app configuration info ``` -------------------------------- ### Accessing Bundle Resources with sys.get_application_path Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/file-access.md Access files bundled with your application by first getting the application's base path. This example demonstrates reading a common file. ```lua local path = sys.get_application_path() local f = io.open(path .. "/mycommonfile.txt", "rb") local txt, err = f:read("*a") if not txt then print(err) return end print(txt) ``` -------------------------------- ### Get Application Info Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/sys-lua.md Retrieves application information, checking if a specific application is installed. Requires platform-specific configuration for iOS (LSApplicationQueriesSchemes) and uses package identifiers for Android. ```lua sysinfo = sys.get_sys_info() twitter = {} if sysinfo.system_name == "Android" then twitter = sys.get_application_info("com.twitter.android") elseif sysinfo.system_name == "iPhone OS" then twitter = sys.get_application_info("twitter:") end if twitter.installed then -- twitter is installed! end ``` ```plist ... LSApplicationQueriesSchemes twitter ... ``` -------------------------------- ### Script Component Setup (Lua) Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/compute.md Initializes a compute-ready texture and sets up input/output textures for the compute program. The texture must be created with usage flags for storage and sampling. ```lua -- In a .script file -- Here we specify the input texture that we later will bind to the -- compute program. We can assign this texture to a model component, -- or enable it to the render context in the render script. go.property("texture_in", resource.texture()) function init(self) -- Create a texture resource like usual, but add the "storage" flag -- so it can be used as the backing storage for compute programs local t_backing = resource.create_texture("/my_backing_texture.texturec", { type = graphics.TEXTURE_TYPE_IMAGE_2D, width = 128, height = 128, format = graphics.TEXTURE_FORMAT_RGBA32F, flags = graphics.TEXTURE_USAGE_FLAG_STORAGE + graphics.TEXTURE_USAGE_FLAG_SAMPLE, }) local textures = { texture_in = resource.get_texture_info(self.texture_in).handle, texture_out = resource.get_texture_info(t_backing).handle } -- notify the renderer of the input and output textures msg.post("@render:", "set_backing_texture", textures) end ``` -------------------------------- ### SetupCallback Source: https://github.com/defold/defold.github.io/blob/master/llms-apis.txt Sets up a Lua callback, managing the stack for instance, context, callback, and self. ```APIDOC ## SetupCallback ### Description The Lua stack after a successful call: ``` [-4] old instance [-3] context table [-2] callback [-1] self ``` In the event of an unsuccessful call, the Lua stack is unchanged ### Parameters - `cbk` (LuaCallbackInfo*) - Lua callback struct ### Returns - `true` (bool) - if the setup was successful ``` -------------------------------- ### Get All GUI Layouts in Defold Source: https://github.com/defold/defold.github.io/blob/master/_posts/2025-10-08-Defold-1-11-1.md Example of how to retrieve all available GUI layouts and their sizes. The function returns a table where keys are layout IDs and values are size objects. ```lua local layouts = gui.get_layouts() for id, size in pairs(layouts) do print(id, size.x, size.y) end ``` -------------------------------- ### Initialize Profiling System Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/engine-dlib-src-dmsdk-dlib-profile-h.md Call ProfileInitialize to set up the profiling system before use. ```c ProfileInitialize(); ``` -------------------------------- ### Base Info.plist Manifest Example Source: https://github.com/defold/defold.github.io/blob/master/llms-manuals.txt This XML demonstrates a base Info.plist structure with various data types and merge strategy attributes. Use this as a starting point for your application's manifest. ```xml NSAppTransportSecurity NSExceptionDomains foobar.net testproperty INT 8 REAL 8.0 BASE64 SEVMTE8gV09STEQ= Array1 Foobar a Array2 Foobar a ``` -------------------------------- ### Animate and Play Particle Effect Source: https://github.com/defold/defold.github.io/blob/master/llms-examples.txt Starts a particle effect and animates the game object's position. This example demonstrates how particle emission space affects behavior when the emitter moves. ```lua function init(self) particlefx.play("#particles") -- <1> go.animate(".", "position.y", go.PLAYBACK_LOOP_PINGPONG, 500, go.EASING_INOUTSINE, 4) -- <2> end --[[ 1. Start playing the particle effect in component "particles" in this game object. 2. Animate this object position on Y axis up and down forever ]] ``` -------------------------------- ### fbinstant.start_game Source: https://github.com/defold/defold.github.io/blob/master/extension-fbinstant/index.md Indicates that the game is ready to start. A callback is invoked upon completion. ```APIDOC ## fbinstant.start_game(callback) ### Description Indicate that the game is ready to start. ### Parameters * `callback` (function) - Function to call when the game has started. The callback function accepts `self` (userdata) and `success` (boolean). ### Callback Parameters * `self` (userdata) - Script self reference * `success` (boolean) - Indicating if the operation was successful or not ``` -------------------------------- ### Initialize Logging System in C++ Source: https://github.com/defold/defold.github.io/blob/master/llms-apis.txt Initialize the Defold logging system. This is required to start the log server. Startup errors are reported to stderr. ```cpp void dmLogInitialize(const LogParams* params); ``` -------------------------------- ### Get Application Info Source: https://github.com/defold/defold.github.io/blob/master/llms-apis.txt Retrieves application information, checking if an application is installed. On iOS, 'app_string' is a URL scheme; ensure it's listed in Info.plist. On Android, it's the package identifier. ```lua sysinfo = sys.get_sys_info() twitter = {} if sysinfo.system_name == "Android" then twitter = sys.get_application_info("com.twitter.android") elseif sysinfo.system_name == "iPhone OS" then twitter = sys.get_application_info("twitter:") end if twitter.installed then -- twitter is installed! end ``` ```xml ... LSApplicationQueriesSchemes twitter ... ``` -------------------------------- ### Bundle Resources Example Source: https://github.com/defold/defold.github.io/blob/master/llms-manuals.txt List directories containing resource files to be copied into the package. Paths are relative to the project root. Use sys.get_application_path() to construct absolute paths for access. ```text bundle_resources Bundle resources are additional files and folders located as a part of your application bundle using the [*Bundle Resources* field](#manuals:project-settings) in *game.project*. The *Bundle Resources* field should contain a comma separated list of directories containing resource files and folders that should be copied as-is into the resulting package when bundling. The directories must be specified with an absolute path from the project root, for example `/res`. The resource directory must contain subfolders named by `platform`, or `architecture-platform`. Supported platforms are `ios`, `android`, `osx`, `win32`, `linux`, `web`, `switch` A subfolder named `common` is also allowed, containing resource files common for all platforms. Example: ``` res ├── win32 │ └── mywin32file.txt ├── common │ └── mycommonfile.txt └── android ├── myandroidfile.txt └── res └── xml └── filepaths.xml ``` You can use [`sys.get_application_path()`](https://defold.com/ref/stable/sys/#sys.get_application_path:) to get the path to where the application is stored. Use this application base path to create the final absolute path to the files you need access to. Once you have the absolute path of these files you can use the `io.*` and `os.*` functions to access the files. Loading bundle resources is covered in more detail in the [File Access manual](#manuals:file-access). ``` -------------------------------- ### Initialize and Connect to Photon Realtime Source: https://github.com/defold/defold.github.io/blob/master/extension-photon-realtime/index.md Initializes the Photon Realtime extension with a callback for handling events and then connects to the Photon server. Ensure the callback function is defined to process connection status, responses, and custom events. ```lua local EVENT_POSX = 1 local EVENT_POSY = 2 function init(self) -- initialize realtime -- the callback function will receive events from photon realtime.init(app_id, app_version, function(self, id, data) -- handle errors if data.error_code and data.error_code > 0 then print(data.error_string) return end -- check responses and events, some examples below if id == realtime.EVENT_CONNECTRETURN then print("connected!") -- join or create a random room realtime.join_or_create_random_room(game_id, room_options, join_options) elseif id == realtime.EVENT_JOINRANDOMORCREATEROOMRETURN then print(data.local_player_nr) -- raise a custom event with position data local pos = go.get_position() realtime.raise_event(false, pos.x, EVENT_POSX) realtime.raise_event(false, pos.y, EVENT_POSY) elseif message_id == realtime.EVENT_CUSTOMEVENTACTION then -- custom events sent using realtime.raise_event() end up here if data.event_code == EVENT_POSX then print(data.event_content) end end end) -- connect to server realtime.connect({}) end function update(self, dt) -- call frequently to check for events realtime.update() end ``` -------------------------------- ### Modify Linear Damping of Collision Object Source: https://github.com/defold/defold.github.io/blob/master/llms/apis/physics-lua.md Get and set the 'linear_damping' property of a collision object. Valid values range from 0 (no damping) to 1 (full damping). This example increases damping by 10% if it's below 0.9. ```lua -- get linear damping from collision object "collisionobject" in gameobject "floater" local target = "floater#collisionobject" local damping = go.get(target, "linear_damping") -- increase it by 10% if it's below 0.9 if damping <= 0.9 then go.set(target, "linear_damping", damping * 1.1) end ``` -------------------------------- ### Accessing Directory Children in Defold Editor Scripts Source: https://github.com/defold/defold.github.io/blob/master/_posts/2025-06-10-Defold-1-10-2.md Use the 'children' property to get a list of resources within a directory in Defold editor scripts. This example demonstrates how to ensure an atlas contains all images from a specified directory. ```lua local images = editor.get("/assets/images", "children") local atlas = "/assets/main.atlas" local txs = {editor.tx.clear(atlas, "images")} for i = 1, #images do local resource_path = editor.get(images[i], "path") if resource_path:match(".png$") ~= nil then txs[#txs + 1] = editor.tx.add(atlas, "images", {image = resource_path}) end end editor.transact(txs) ``` -------------------------------- ### Box2D Physics Body Manipulation in Lua Source: https://github.com/defold/defold.github.io/blob/master/_posts/2024-04-29-Defold-1-8-0.md Access and manipulate Box2D physics bodies using the `b2d` Lua module. This example shows how to get a body, apply linear impulses, and includes a debug print function. ```lua local id = factory.create("#factory", position) local url = msg.url(nil, id, "collisionobject") -- get the collision object in the spawned object self.body = b2d.get_body(url) -- get the b2body object b2d.body.dump(self.body) -- debug print -- add an impulse local pos = b2d.body.get_position(self.body) b2d.body.apply_linear_impulse(self.body, vmath.vector3(300,200,0), pos + vmath.vector3(16,16,0)) ``` -------------------------------- ### Install and Preload libffi Source: https://github.com/defold/defold.github.io/blob/master/_includes/shared/en/linux-faq.md Download and install libffi7, then use LD_PRELOAD to specify the path to libffi.so.7 when running Defold to resolve 'libffi.so' version mismatch crashes. ```bash $ wget http://ftp.br.debian.org/debian/pool/main/libf/libffi/libffi7_3.3-6_amd64.deb $ sudo dpkg -i libffi7_3.3-6_amd64.deb ``` ```bash $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libffi.so.7 ./Defold ``` -------------------------------- ### Initialize Script and Bounding Box Source: https://github.com/defold/defold.github.io/blob/master/_includes/examples/model/aabb/aabb_script.md Sets up input focus, gets camera rotation, creates a new bounding box, and populates the scene with initial cubes. ```lua function init(self) -- Acquire input focus to receive input events msg.post(".", "acquire_input_focus") -- Get the camera default rotation self.camera_euler = go.get("/camera", "euler") -- Create a new dynamic bounding box instance sself.bbox = bbox_new() -- Add some cubes to the scene at (0, 1-5, 0) coordinates for i = 1, 10 do local cube_color = i % 2 == 0 and "red" or "white" add_cube(self, (math.random() - 0.5) * 0.1, i / 2, (math.random() - 0.5) * 0.1, cube_color) end bbox_update_all(self.bbox) -- Compute the initial bounding box data self.view = bbox_compute(self.bbox) end ``` -------------------------------- ### Define and Use Custom Square Wave Easing Source: https://github.com/defold/defold.github.io/blob/master/llms/examples/animation/custom_easing.md Define a custom easing curve using a Lua table and apply it to an animation. This example uses a square wave pattern, causing the animation to snap between start and target values. ```lua local VALUES = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, } local SQUARE_EASING = vmath.vector(VALUES) function init(self) go.animate(".", "position.y", go.PLAYBACK_LOOP_FORWARD, 520, SQUARE_EASING, 4.0) end ``` -------------------------------- ### Runtime Access to Project Settings Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/project-settings.md Demonstrates how to retrieve project settings at runtime using Defold's sys.get_config_* functions. Keys are formed by category and setting names separated by a dot. ```lua local title = sys.get_config_string("project.title") local gravity_y = sys.get_config_number("physics.gravity_y") ``` -------------------------------- ### Install Homebrew on macOS Source: https://github.com/defold/defold.github.io/blob/master/README.md Installs Homebrew, a package manager for macOS, which is a prerequisite for installing Ruby. ```sh /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Install Haxe using Homebrew Source: https://github.com/defold/defold.github.io/blob/master/_posts/2021-04-26-Creator-Spotlight-Adam-Engebretson.md Use this command to install Haxe if you are using macOS and have Homebrew installed. ```bash brew install haxe ``` -------------------------------- ### Start Python 3 HTTP Server (Alternative) Source: https://github.com/defold/defold.github.io/blob/master/llms/manuals/html5.md An alternative command to start a simple HTTP server for testing HTML5 builds in Python 3. ```sh python3 -m http.server ```