You are not logged in.
Pages: 1
These scripts replace the native ds functions to allow naming instead of ids. For example, instead of
ds_map_add(id, key, value)
you get
DS_map_add(name, key, value)
This is the initialization script:
/*
** 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):
/*
** 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:
/*
** 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:
/*
** 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.
var 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.
if (ID != -1)
{
//blah blah blah...
}
else
{
return -1;
}
This checks if we found the id of the particular data structure.
var 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:
/*
** 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.
Offline
Pages: 1