Created
March 21, 2019 10:46
-
-
Save NovemberDev/9a83e9abe1f4962f2bc99d04ac98dd41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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