{"id":16131449,"url":"https://github.com/calinou/godot-snippets","last_synced_at":"2025-07-25T13:42:32.092Z","repository":{"id":49778126,"uuid":"49452093","full_name":"Calinou/godot-snippets","owner":"Calinou","description":"Code snippets for use with the Godot Engine","archived":false,"fork":false,"pushed_at":"2016-01-11T20:54:56.000Z","size":3,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T12:34:44.427Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://godotengine.org","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Calinou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-11T20:22:24.000Z","updated_at":"2025-01-29T14:55:08.000Z","dependencies_parsed_at":"2022-08-29T17:40:25.155Z","dependency_job_id":null,"html_url":"https://github.com/Calinou/godot-snippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Calinou%2Fgodot-snippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Calinou%2Fgodot-snippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Calinou%2Fgodot-snippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Calinou%2Fgodot-snippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Calinou","download_url":"https://codeload.github.com/Calinou/godot-snippets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247495805,"owners_count":20948110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T22:25:11.991Z","updated_at":"2025-04-06T14:32:30.317Z","avatar_url":"https://github.com/Calinou.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# godot-snippets\n\n**A list of useful Godot snippets.**\n\n## Basics\n\n### Instancing a scene by code\n\n```gdscript\nvar scene_file = preload(\"res://path/to/scene_file.tscn\")\nvar scene_instance = scene_file.instance()\nadd_child(scene_instance)\n```\n\n### Play some music\n\n```gdscript\nfunc play(music):\n\tvar stream = load(\"res://\" + str(music) + \".opus\")\n\tget_node(\"StreamPlayer\").set_stream(stream)\n\tget_node(\"StreamPlayer\").play()\n```\n\n### Printing only when running from editor, or debug-mode exports\n\n```gdscript\nfunc print_debug(text):\n\tif OS.is_debug_build():\n\t\tprint(text)\n```\n\n### Printing to console with a timestamp\n\n```gdscript\n# YYYY-MM-DD\nfunc get_date():\n\treturn str(OS.get_date()[\"year\"]) + \"-\" + str(OS.get_date()[\"month\"]).pad_zeros(2) + \"-\" + str(OS.get_date()[\"day\"]).pad_zeros(2)\n\n# hh:mm:ss\nfunc get_time():\n\treturn str(OS.get_time()[\"hour\"]).pad_zeros(2) + \":\" + str(OS.get_time()[\"minute\"]).pad_zeros(2) + \":\" + str(OS.get_time()[\"second\"]).pad_zeros(2)\n\n# [YYYY-MM-DD | hh:mm:ss]\nfunc print_timestamp(text):\n\tprint(\"[\" + get_date() + \" | \" + get_time() + \"] \" + text)\n```\n\n### Make a string translatable (with possible replacement)\n\n```gdscript\nfunc _ready():\n\tprint(tr(\"HELLO_WORLD\"))\n\tprint(tr(\"COLLECT_N_APPLES\").replace(\"%s\", str(apples)))\n```\n\n## Advanced\n\n### Game options management using an .ini file\n\n```gdscript\nfunc get_option(section, key, default):\n\tvar config = ConfigFile.new()\n\tconfig.load(\"user://config.ini\")\n\tvar value = config.get_value(section, key, default)\n\treturn value\n\nfunc set_option(section, key, value):\n\tvar config = ConfigFile.new()\n\tconfig.load(\"user://config.ini\")\n\tconfig.set_value(section, key, value)\n\tconfig.save(\"user://config.ini\")\n```\n\n## License\n\nCopyright (c) 2016 Calinou and contributors  \nThis file and all snippets included are under CC0 1.0 Universal. See `LICENSE.md` for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalinou%2Fgodot-snippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalinou%2Fgodot-snippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalinou%2Fgodot-snippets/lists"}