Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Parsing Command Line Arguments

Dylan Dumesnil edited this page Jun 30, 2020 · 1 revision

The class MDArguments provides many helpers for checking and parsing the command line arguments that your game launched with.

To check if a particular argument exists:

if (MDArguments.HasArg("logprofile"))
{
    MDLog.Info(LOG_CAT, "Profiling [{0}] took {1}us", ProfileName, GetMicroSeconds());
}

To get the value that an argument was set to, you can use MDArguments.GetArg(), MDArguments.GetArgInt(), or MDArguments.GetArgFloat(), depending on what type you need:

// Expects -server=port
if (MDArguments.HasArg("server"))
{
    int Port = MDArguments.GetArgInt("server");
    StartServer(Port);
}
// Expects -client=[IPAddress:Port]
else if (MDArguments.HasArg("client"))
{
    string ClientArg = MDArguments.GetArg("client");
    string[] HostPort = ClientArg.Split(":");
    StartClient(HostPort[0], HostPort[1].ToInt());
}
Clone this wiki locally