Skip to content

Instantly share code, notes, and snippets.

@NovemberDev
Created March 21, 2019 10:46
Show Gist options
  • Save NovemberDev/9a83e9abe1f4962f2bc99d04ac98dd41 to your computer and use it in GitHub Desktop.
Save NovemberDev/9a83e9abe1f4962f2bc99d04ac98dd41 to your computer and use it in GitHub Desktop.
# godot_command_line.gd
# by: @november_dev
#
# Parse command line arguments in an exported project
#
# Command:
# /path/to/executable "res://scene.tscn" first_value=value second_value=value
#
# Sample:
#
# godot_command_line.get_arg("first_value", "defaultValueIfNull")
extends Node
# key value pair of arg-name and arg-value
var args = {}
func _ready():
for cmd in OS.get_cmdline_args():
if cmd.find("=") != -1:
var v = cmd.split("=")
args[v[0]] = v[1]
print("Args found: " + str(args.size()))
func get_arg(name, defaultIfNull):
return (args[name] if args.has(name) else defaultIfNull)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment