![]() |
Reply From: | Calinou |
You can use OS.get_cmdline_args()
for this. However, you’ll have to parse command-line arguments yourself. Due to how Godot currently parses them, there are a few limitations to be aware of:
- Command-line arguments should be written in the form
--key=value
. Godot will try to openvalue
as if it was a scene file if you use--key value
. - Custom command-line arguments shouldn’t conflict with engine arguments.
If this is too limiting, you can also use environment variables using OS.get_environment()
instead.
PS: You can set Editor → Main Run Args in the Project Settings to define command-line arguments to be passed by the editor when running the project.
To parse command-line arguments into a dictionary, you could use something like this:
var arguments = {}
for argument in OS.get_cmdline_args():
# Parse valid command-line arguments into a dictionary
if argument.find("=") > -1:
var key_value = argument.split("=")
arguments[key_value[0].lstrip("--")] = key_value[1]
Is it possible to parse command line arguments with exported game binaries as well?
slasktotten | 2020-01-23 09:47
Thanks a lot
supper_raptor | 2020-10-03 12:43
Can you give an example of how to work with
Editor → Main Run Args
?
avnih | 2021-05-26 07:15