### Initialization Example Source: https://docs.godotengine.org/en/latest/classes/class_mobilevrinterface.html Example of how to find and initialize the 'Native mobile' VR interface. ```APIDOC ## Initialization Example ### Description This code snippet demonstrates how to find the 'Native mobile' VR interface provided by XRServer and initialize it. If initialization is successful, it enables VR usage for the viewport. ### Method ```gdscript var interface = XRServer.find_interface("Native mobile") if interface and interface.initialize(): get_viewport().use_xr = true ``` ### Notes Ensure that the necessary input device sensors (accelerometer, gyroscope, etc.) are enabled in Project Settings for Android. ``` -------------------------------- ### Set/Get Start Position Source: https://docs.godotengine.org/en/latest/classes/class_navigationpathqueryparameters2d.html Allows setting and getting the pathfinding start position in global coordinates. ```APIDOC ## Set/Get Start Position ### Description Manages the starting point for pathfinding queries in global 2D coordinates. ### Method - `set_start_position(value: Vector2)`: Sets the pathfinding start position. - `get_start_position()`: Returns the current pathfinding start position. ### Parameters #### Path Parameters - **start_position** (Vector2) - The pathfinding start position in global coordinates. Defaults to `Vector2(0, 0)`. ``` -------------------------------- ### C++ For Loop Examples Source: https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_advanced.html Provides examples of C-style for loops in C++ with different starting points, conditions, and increment steps. ```cpp for (int i = 0; i < 10; i++) {} for (int i = 5; i < 10; i++) {} for (int i = 5; i < 10; i += 2) {} ``` -------------------------------- ### Basic TCPServer Setup and Connection Handling Source: https://docs.godotengine.org/en/latest/classes/class_tcpserver.html This example demonstrates how to initialize a TCPServer, listen on a specific port, and accept incoming connections. Replace the 'use_stream' function content with your specific logic for handling client data. ```GDScript extends Node; const DEFAULT_PORT: int = 19388; var server: TCPServer; func use_stream(stream: StreamPeerTCP): # Your Code Here pass; func _ready(): server = TCPServer.new(); server.listen(DEFAULT_PORT); func _process(_dt: float): while server.is_connection_available(): var stream: StreamPeerTCP = server.take_connection(); use_stream(stream); ``` -------------------------------- ### Example Server Output Source: https://docs.godotengine.org/en/latest/tutorials/networking/websocket.html This output demonstrates a successful server startup and a client connection, including receiving and echoing a text packet. ```text Server started. + Peer 2 connected. < Got text data from peer 2: Test packet ... echoing ``` -------------------------------- ### Example Output of WebRTC Chat Source: https://docs.godotengine.org/en/latest/tutorials/networking/webrtc.html This is an example of the console output when two peers successfully exchange messages using the WebRTC setup. ```text /root/main/@@3 received: Hi from /root/main/@@2 /root/main/@@2 received: Hi from /root/main/@@3 ``` -------------------------------- ### Cut Video Segment with FFmpeg Source: https://docs.godotengine.org/en/latest/tutorials/animation/creating_movies.html Trim a video by specifying the start time and duration. This example keeps 5.2 seconds of video starting from 12.1 seconds. ```bash ffmpeg -i input.avi -ss 00:00:12.10 -t 00:00:05.20 -crf 15 output.mp4 ``` -------------------------------- ### Set up DTLS Server and Handle Connections (C#) Source: https://docs.godotengine.org/en/latest/classes/class_dtlsserver.html This C# example demonstrates how to set up a DTLS server using a private key and certificate, listen for UDP connections, and accept DTLS clients. It includes logic for polling peers and handling incoming/outgoing DTLS packets. Note that some initial connections may fail due to the cookie exchange process. ```csharp // ServerNode.cs using Godot; public partial class ServerNode : Node { private DtlsServer _dtls = new DtlsServer(); private UdpServer _server = new UdpServer(); private Godot.Collections.Array _peers = []; public override void _Ready() { _server.Listen(4242); var key = GD.Load("key.key"); // Your private key. var cert = GD.Load("cert.crt"); // Your X509 certificate. _dtls.Setup(TlsOptions.Server(key, cert)); } public override void _Process(double delta) { while (_server.IsConnectionAvailable()) { PacketPeerUdp peer = _server.TakeConnection(); PacketPeerDtls dtlsPeer = _dtls.TakeConnection(peer); if (dtlsPeer.GetStatus() != PacketPeerDtls.Status.Handshaking) { continue; // It is normal that 50% of the connections fails due to cookie exchange. } GD.Print("Peer connected!"); _peers.Add(dtlsPeer); } foreach (var p in _peers) { p.Poll(); // Must poll to update the state. if (p.GetStatus() == PacketPeerDtls.Status.Connected) { while (p.GetAvailablePacketCount() > 0) { GD.Print($ ``` -------------------------------- ### Getting Physical Keycode String Representation Source: https://docs.godotengine.org/en/latest/classes/class_inputeventkey.html Example demonstrating how to get a human-readable string representation of a physical keycode using `OS.get_keycode_string()` in combination with `DisplayServer` functions. ```APIDOC ## Getting Physical Keycode String Representation ### Description This example shows how to obtain the human-readable string for a physical keycode by converting it to a keycode and label using `DisplayServer` functions and then using `OS.get_keycode_string()`. ### GDScript Example ```gdscript func _input(event): if event is InputEventKey: var keycode = DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode) var label = DisplayServer.keyboard_get_label_from_physical(event.physical_keycode) print(OS.get_keycode_string(keycode)) print(OS.get_keycode_string(label)) ``` ### C# Example ```csharp public override void _Input(InputEvent @event) { if (@event is InputEventKey inputEventKey) { var keycode = DisplayServer.KeyboardGetKeycodeFromPhysical(inputEventKey.PhysicalKeycode); var label = DisplayServer.KeyboardGetLabelFromPhysical(inputEventKey.PhysicalKeycode); GD.Print(OS.GetKeycodeString(keycode)); GD.Print(OS.GetKeycodeString(label)); } } ``` ``` -------------------------------- ### C# "Hello, world!" Example Source: https://docs.godotengine.org/en/latest/engine_details/editor/index.html A basic C# example to print "Hello, world!" to the console. This demonstrates the syntax for outputting text in C# within Godot. ```csharp using Godot; public class HelloWorld : Node { public override void _Ready() { GD.Print("Hello, world!"); } } ``` -------------------------------- ### Complete Script GDScript Example Source: https://docs.godotengine.org/en/latest/tutorials/scripting/index.html A complete GDScript example that combines node setup and basic movement. This script is attached to a Node2D and prints a message when ready. ```gdscript extends Node2D func _ready(): print("Hello, world!") func _process(delta): position.x += 100 * delta ```