GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Script Submission » replacement ds scripts » 2013-07-11 15:04:00

waaaaaaah
Replies: 0

These scripts replace the native ds functions to allow naming instead of ids. For example, instead of

Expandds_map_add(id, key, value)

you get

ExpandDS_map_add(name, key, value)

This is the initialization script:

Expand/*
**  Usage:
**      DS_init();
**
**  Arguments: 
**      None
**
**  Returns: 
**      Nothing
**
**  Notes:
**      This script initializes map data structures that will hold the name 
**      and index of each data structure it (the map) is associated with. 
**      This should be called as soon as possible, preferably at the start of the game.
**
**  GMLscripts.com
*/
{
    global.dsMap = ds_map_create();
    global.dsGrid = ds_map_create();
    global.dsList = ds_map_create();
    global.dsStack = ds_map_create();
    global.dsQueue = ds_map_create();
    global.dsPriorityQueue = ds_map_create();
}

Since I only personally had usage for map, grids, and lists, I only created scripts for those. It should be easy though to adapt the following scripts to include the others.

Okay. The format for creating a new data structure is as so(I'll use the map ds for examples):

Expand/*
**  Usage:
**      DS_map_create(name);
**
**  Arguments:
**      name           the name of the map data structure to be created
**
**  Returns:
**      Nothing
**
**  Notes:
**      This script creates a new map data structure, and adds its id and the name to refer
**       to it to another map data structure.
**
**  GMLscripts.com
*/
{
    var name,map;
    name = argument0;
    map = ds_map_create();
    ds_map_add(global.dsMap,name,map);
}

Basically, as above. You'll have to add more arguments for grids, but that's expected.

The next one is for finding the id of a particular data structure you want to work with. This is needed for every other script  since you need its id to do ANYTHING with it.
Behold:

Expand/*
**  Usage:
**      id = DS_map_get_id(name);
**
**  Arguments:
**      name           name of map data structure whose id is to be returned
**
**  Returns:
**      id           the id of the named map data structure
**
**  Notes:
**      If the particular map data structure is not found, a value of -1 is returned
**
**  GMLscripts.com
*/
{
    var name;
    name = argument0;

    if (ds_map_exists(global.dsMap,name)) {
        return ds_map_find_value(global.dsMap,name);
    }
    else {
        return -1;
    }
}

Pretty simple. No loops required :)

Next, for destroying a data structure:

Expand/*
**  Usage:
**      DS_map_destroy(name);
**
**  Arguments:
**      name           the name of the map data structure to be deleted
**
**  Returns:
**      Nothing           
**
**  Notes:
**      If the id of the particular map data structure isn't found, 
**      a value of -1 is returned. This script depends on the scripts 
**      DS_init and DS_map_get_id
**
**  GMLscripts.com
*/
{
    var name,ID;
    name = argument0;
    ID = DS_map_get_id(name);
    if (ID != -1) {
        ds_map_destroy(ID);
        ds_map_delete(global.dsMap,name);
    }
    else {
        return -1;
    }
}

Again, very simple stuff.

Next up is a general breakdown of how any other replacement script should look, since I've covered the basics of it with the above scripts.

Expandvar name, ID;
name = argument0;
ID = DS_(data structure name here)_get_id(name);

This gets called first, so we can get our data structure id to work with.

Expandif (ID != -1)
    {
        //blah blah blah...
    }
else
    {
        return -1;
    }

This checks if we found the id of the particular data structure.

Expandvar key, value;
        key = argument1;
        value = argument2;
        ds_map_add(ID, key, value);

This is whatever function of the data structure you are replacing is. The above code is for ds_map_add. Simply add arguments and the native function, and presto! Instant replacement! :)

Also, here's a replacement for the ds_grid_resize function for gm6 users:

Expand/*
**  Usage:
**      DS_grid_resize_gm6(name,w,h);
**
**  Arguments:
**      name           the name of the grid data structure to resize
**      w,h           the new width and height of the grid data structure
**
**  Returns:
**      Nothing
**
**  Notes:
**      Since gm6 has a bug when it comes to resizing a grid, this 
**      script here is perfect for that.
**      The bug only activates widthwise, so you can still use the 
**      regular DS_grid_resize for height resizes
**
**  GMLscripts.com
*/
{
    var name,w,h,ID;
    name = argument0;
    w = argument1;
    h = argument2;
    ID = DS_grid_get_id(name);

    if (ID != -1) {
        DS_grid_create("temp",w,h);
        var i, t;
        for (t=0; t<h; t+=1){
        for (i=0; i<w; i+=1){
            var val;
            val = DS_grid_get(name,i,t);
            DS_grid_set("temp",i,t,val);
        } 
        }
        DS_grid_destroy(name);
        ds_map_add(global.dsGrid,name,DS_grid_get_id("temp"));
        ds_map_delete(global.dsGrid,"temp");
    }
    else {
        return -1;
    }
}

It's not pretty, but it will do the job if you need it. DS_grid_create, destroy, set, get, and get_id are all replacement versions of the grid functions.

#2 Re: Off Topic » Pycap - Python meets the PopCap framework » 2008-03-27 09:38:43

lol. I played ROM CHECK FAIL, and it's very interesting. A very unique way of playing a game. I almost beat it too, but then I died sad

#3 Re: Community » Introductions » 2008-01-09 14:26:37

Hello, I'm waaaaaaah, also know by the same name on the GMC. I seem to have started GM the latest, as I came aboard for GM 6.0. I have not made a game yet, though I have tried. My current attempt is an RPG, which I am rewriting due to the fact that I was getting disinterested. I've been using GM since December '04. I know GML pretty well, have tried to learn ANSI C, failed, and am going to try my hand at another language soon.
I have submited a dobule jump example to the GMC, and I plan soon to release my custom key scripts there as well(maybe you could find a use for it here too XD).
I'm a member of a team developing Starfox 2D: a 2D version of Starfox 64.
I like reading, playing video games, and of course, game making biggrin.

#4 Re: Off Topic » Preposterous Code » 2008-01-09 14:12:45

Wow. This script could certainly use a cleanup.

Board footer

Powered by FluxBB