Skip to content

Import and Use

Grisgram edited this page Sep 1, 2024 · 2 revisions

Step 1: Import the local package

  • Go to the page of the latest release.
  • Download the CommandLineArgs.yymps file
  • Open your GameMaker Project
  • Select Tools -> Import Local Package and choose the downloaded file
  • A Folder CommandLineArgs appears in your Asset Browser

Step 2: How to use the code

There are two possible points in time, where you can use the code:

  1. In a global scope during initialization
  2. In a function or a Create event of any object (like your global GameController, if you have one)

In global scope, if you write code outside of any function, in a script file, you have no control over the initialization order of your scripts. You simply don't know, "who will run first".

As the CommandLineArgs library offers a global variable through a macro (ARGS), you have no chance, to know, whether this variable is already initialized or not.

For this case, the library offers another macro, ENSURE_ARGS which you should call before accessing the ARGS macro.

A short example, for better understanding:

// global scope, outside of any function
// this will run before the first room, when everything is initalized

ENSURE_ARGS;
if (ARGS.has_option("fullscreen"))
   window_set_fullscreen(true);

Tip

The ENSURE_ARGS macro only needs to be called, when running in global scope. If you analyze your commandline arguments in the Create event of any controller object, it is guaranteed, that the ARGS global already has a value and the commandline has been analyzed.


Now find out, how to use the ARGS class in the Functions page.

Clone this wiki locally