Extension Retrieve hard drive partition information in Game Maker

Discussion in 'Tutorials' started by Rafsun82, Jul 13, 2016.

  1. Rafsun82

    Rafsun82 Guest

    How to retrieve hard drive partition information in Game Maker by using
    Hard Disk Info
    extension by Rafsun82​

    GM Version
    : GM8 and GM:S
    Target Platform: Windows
    Download: Download from Dropbox (ZIP)
    Links: Original Website Post


    Summary:
    By following this tutorial, you will learn how to get hard drive partition information in Game Maker. Like- total partition number, drive letter, volume label, total size, total frees pace, drive type and drive format. You need to download a extension package Hard Disk Info written by me. Link is posted above.

    An example GMK file, extension package GEX file and a manual HTML file is included in the download.


    Tutorial:
    Download the ZIP archive. Extract it. Install and add the extension package (named HardDIskInfo.gex) to your Game Maker 8 or Game Maker: Studio project.

    Note: Check the manual file to learn about available functions in the extension and how to use them.

    In this tutorial, we want that the game to draw all partitions information in the screen. Like this -

    [​IMG]
    And also want that the game should response when we insert a drive (Ex- Removal disk) in the computer.

    So, simply we will create a variable named "text" and all information will be put in there with decoration. Then we will draw this to the screen in draw event.

    At first create a script named "make_list". This will fetch all information and decorate them as a string and put the string in the variable "text".
    Codes in the script should look like-
    Code:
    {
        n = hdd_count()-1;
        text = "";
        for ( i =0; i <= n; i += 1;)
        {
            text += hdd_letter(i)+" "+hdd_label(i)+" ("+hdd_type(i)+") ("+hdd_format(i)+")#";
            text += string(hdd_convert( hdd_freespace(i), 1))+" GB free of "+string(hdd_convert( hdd_size(i), 1))+" GB#";
            text += "#";
        }
    }
    This is so messy but you know what it will do. Clears previous value of "text" then add new values.

    Now, in the Create event declare "text" variable first then call the "make_list" script. Then in the Draw event, simply draw the string values of "text". Run the game and if everything okay, we can proceed to next.

    We want that if a removal disk is inserted then the game should draw it's information too. In the create event add this code:
    Code:
    old_total = hdd_count();
    This variable is to hold total number for partitions. And it won't change if a new disk is inserted after running, because we put this code in Create event. Now we it's easy to determine if new disk inserted by comparing "old_total" variable with "hdd_count" (this funciton returns total partition number) function. We must put the code for this task in step event:
    Code:
    if hdd_count() != old_total
    {
        make_list();
        old_total = hdd_count();
    }
    This will simply detect, if the number of total partition changed. And if it changed then it will remake the list. And then update the "old_total" variable.

    Run the game. Then insert a drive and notice the change in the screen. Then remove it again. The screen will change again.

    If something went wrong, follow all the steps from the beginning again. Or don't mind to post a reply. Thanks for using it. Sorry for any grammatical or spelling mistake. If this tutorial is helpful Like this post. :)
    There is my website if you have time - http://r82.net23.net/home.
     
    Last edited by a moderator: Jul 13, 2016

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice