Skip to content

FileDropper

Michael edited this page Aug 23, 2022 · 2 revisions

Once in a while, you might find yourself wanting to allow the user to drag and drop files from Windows Explorer (or the desktop, or elsewhere) onto the program window. GameMaker doesn't have a built-in way to let us do that. Fortunately, we're allowed to link DLLs, meaning on Windows we can go around GameMaker to do (almost) anything we want. This is a Windows-only extension.

You need to disable the filesystem sandbox (found in Game Options > Windows) if you want to actually be able to use the dropped files.

Relevant Links

It's on Itch:

There's a Marketplace version but it's pretty out-of-date and, honestly, the Marketplace is a complete mess that I don't have time to deal with.

API

It's pretty simple.

file_dropper_get_files(extensions*)

Returns: array of strings

Parameter Type Description
extensions string or array of strings A file extension or array of file extensions that will be filtered for (optional; leaving it blank returns all files)

Returns an array of filenames that have been dropped onto the program window. If no files have been dropped onto the window, the array will have zero elements. The filenames are sorted alphabetically. Generally, you would call this in one of the Step events. The file dropper is flushed automatically every update, and the array will only be returned once. See the demo on itch.io above for an example.

You can pass in a file extension if you only want to see dropped files of a certain type, including the leading dot, or an array of file extensions if you only want to see dropped files of several types. This is useful if you're looking to load only a specific kind of dropped file.

file_dropper_get_files(".png")

This will return only dropped files with the PNG extension.

file_dropper_get_files([".png", ".jpg", ".jpeg", ".bmp"])

This will return only dropped files with PNG, JP[E]G, or bitmap extensions.

file_dropper_flush()

Returns: n/a

Clears the list of dropped files. Generally you want to call this after getting the list from file_dropper_get_files() if you don't want the same list to be returned multiple times.

file_dropper_version()

Returns: n/a

Prints out a string showing the version number of the extension (both the DLL and the GML). It's probably not going to get any higher than whatever it is now, but that's what I said the last time and then I updated it anyway so who knows.

Clone this wiki locally