Jump to content


Photo

Gm Database System v10.3


  • Please log in to reply
86 replies to this topic

#1 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 10 August 2009 - 06:54 AM

This extension package made exclusively in GML adds support for a new data structure in GM: tables. Tables are very similar to lists (which are built-in in GM). The major difference is that the items they contain consist of multiple fields.

Download (v10.3): http://www.benetonfi...emp/gmdb103.zip
Help File: http://www.benetonfi...mdb103_doc.html
Changes Log: http://www.benetonfi...mdb_changes.txt

NOTE: This extension was written for GM 8.1 but it should be compatible with GM: Studio. I am planning on making a new version specifically for GM: Studio in the future.


Edited by benetonmovie, 14 June 2013 - 04:05 PM.

  • 2

#2 sabriath

sabriath

    12013

  • GMC Member
  • 3149 posts

Posted 10 August 2009 - 08:08 AM

Uhm...wouldn't it be simpler to just make it a double array?

Instead of a table with first name, last name and age like in the example, it would be:

first_name = 0;
last_name = 1;
age = 2;

table[0,first_name] = "James";
table[0,last_name] = "Beethoven";
table[0,age] = 32;
Just saying, I am not seeing any differences between a table that couldn't be done in a double array that is built-in to GM. Although some of the functionalities (such as sort and shuffle) would be nice to have for both single AND double arrays, so if you can pull those out of the table functions and package them as a library for use with regular arrays, that would be great! (for others anyway, I don't need them, I use class structures in GM :P ).

Good luck!
  • 0

#3 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 10 August 2009 - 06:15 PM

No, tables are much more powerful than what can be done with arrays. You can delete and insert entries at given positions and others are automatically pushed (just like lists). Also it makes things much more structured and easier to work with (in my opinion). Thanks for the reply!
  • 0

#4 sabriath

sabriath

    12013

  • GMC Member
  • 3149 posts

Posted 17 August 2009 - 07:43 AM

No, tables are much more powerful than what can be done with arrays. You can delete and insert entries at given positions and others are automatically pushed (just like lists). Also it makes things much more structured and easier to work with (in my opinion). Thanks for the reply!

Anything that can be done with a table can be done with arrays.

//'scr_new_list()'
ar_max = -1;

//'scr_add(elem)'
ar_max += 1;
ar_elem[ar_max] = argument0;

//'scr_insertafter(ind, elem)'
for (i=argument0; i<ar_max; i+=1)
{
  ar_elem[i+1] = ar_elem[i];
}
ar_elem[argument0+1] = argument1;
if (argument0 == ar_max) ar_max += 1;

//'scr_delete(ind)'
for (i=argument0; i<ar_max; i+=1)
{
  ar_elem[i] = ar_elem[i+1];
}
ar_max -= 1;

Then again, I could turn an array into a class member if I felt like it:

//'scr_class_init()'
class_first = -1;
class_last = -1;
class_max = -1;

//'scr_class_new(elems)'
i = class_max + 4;
class_max += argument0 + 3;
class_arr[i] = class_last;
class_arr[i+1] = -1;
class_arr[i+2] = argument0;
if (class_first == -1)
{
  class_first = i;
}
else
{
  class_arr[class_last+1] = i;
}
class_last = i;
return i;

//'scr_class_remove(class_ind)'
i = class_arr[argument0];
j = class_arr[argument1+1];
if (i == -1)
{
  class_first = j;
}
else
{
  class_arr[i+1] = j;
}
if (j == -1)
{
  class_last = i;
}
else
{
  class_arr[j] = i;
}

Of course this is a severely dubbed down version (doesn't even show garbage collection). I can do this with pure strings as well :) Let me know if you need any help though, I'm good at helping.
  • 0

#5 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 17 August 2009 - 11:02 AM

Of course, I know it can be done somehow... This extension only uses GML, by the way. But I made it to keep it simple for everyone (myself included) and fast. It uses lists, which are (quoting the GM manual) "implemented using simple arrays but, as this is done in compiled code it is a lot faster than using an array yourself".
  • 0

#6 gmlctl

gmlctl

    GMC Member

  • GMC Member
  • 47 posts
  • Version:Unknown

Posted 24 September 2009 - 08:11 AM

Looking good. Keep up the good work!
  • 0

#7 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 21 October 2009 - 01:42 AM

Thanks! Any suggestion, anyone?
  • 0

#8 meatspider

meatspider

    GMC Member

  • New Member
  • 3 posts

Posted 11 November 2009 - 12:09 AM

i know this is a complete noob question. to use a .gex file i just put it in the extensions folder? (never used one before) i try and it gives me a cannot find extension package gm database syste, when i try to load the example.
  • 0

#9 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 11 November 2009 - 02:07 AM

Please look at this tutorial: http://gmc.yoyogames...howtopic=280300
  • 0

#10 meatspider

meatspider

    GMC Member

  • New Member
  • 3 posts

Posted 11 November 2009 - 10:26 AM

Awesome! thanks. i tried the extensions selection before but didnt see the new one listed so gave up. thanks again!
  • 0

#11 cuetzpalin

cuetzpalin

    GMC Member

  • New Member
  • 7 posts

Posted 22 November 2009 - 07:05 AM

Is it possible to sort entries based on more than one column?
  • 0

#12 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 24 November 2009 - 05:25 AM

No, not at the moment, sorry. I added it to my to-do list! :)
  • 0

#13 SimpleMugen

SimpleMugen

    GMC Member

  • New Member
  • 10 posts

Posted 26 November 2009 - 01:00 PM

nice job! :)
  • 0

#14 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 26 November 2009 - 07:58 PM

Thank you very much for the nice reply! Hoping you're finding it useful!
  • 0

#15 SimpleMugen

SimpleMugen

    GMC Member

  • New Member
  • 10 posts

Posted 26 November 2009 - 11:11 PM

you didn't add one usefull action - select row by 2 or more variables...
i made one, here it is:
/*
argument0 - your table
argument1 - column1
argument2 - column2
argument3 - column3
argument4 - variable that must = column1
argument5 - variable that must = column2
argument6 - variable that must = column3
usage:
SCRIPT_NAME(table id, column 1, column 2, column 3, var = column 1, var = column 2, var = column 3)
in this case script will delete searched entry
*/
var _list,_pos;
_list=ds_list_create()
_pos=db_entry_get_pos_all(argument0,argument1, argument4, _list)
for(i=0;i<ds_list_size(_list);i+=1)
{
	if(argument5=db_entry_get_value(argument0,argument2,ds_list_find_value(_list,i)))
	{
		if(argument6=db_entry_get_value(argument0,argument3,ds_list_find_value(_list,i)))
		{
		//If all ok, return:
		show_message(string('ok on step: '+string(i)+'#(count from zero)'))
		//delete a right entry (where argument1=argument4, argument2=argument5 and argument3=argument6)
		db_entry_delete(argument0,ds_list_find_value(_list,i))
		ds_list_clear(_list)
		exit;
		}
	}
}
hope you add this function in your new release of gex :) (certainly more flexible)
  • 0

#16 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 27 November 2009 - 12:29 AM

Nice script SimpleMugen! However there's already a way to check for more than 1 column, using the function db_entry_get_pos_ext() like this:

db_entry_get_pos_ext(table id, "column1=variable1,column2=variable2,column3=variab
le3
", 0, list, ",");


This function saves in list (must be an existing ds_list ID) all the entries that correspond to the given conditions.

Edited by benetonmovie, 27 November 2009 - 12:31 AM.

  • 0

#17 SimpleMugen

SimpleMugen

    GMC Member

  • New Member
  • 10 posts

Posted 27 November 2009 - 02:29 AM

omg :)
thanks a lot! your gex is great :)
  • 0

#18 brod

brod

    Brian RODriguez

  • GMC Member
  • 2021 posts
  • Version:GM8

Posted 27 November 2009 - 02:36 AM

Ahhh.. I can't thank you enough!! I was trying to create my own database editor, and it was a hell of an annoyance! But this... this is so incredible and simple, thank you!

A suggestion, though.
db_column_get_name/type/default()

Would make your example better, for example your example can do
var exe;
exe = "db_entry_add(" +string(table)+ ", " +string(db_column_count(table))+ ", ";
for(a=0;a<db_column_count(table);a+=1)
	{
	if(db_column_get_type(table, a)==0)
		{
		exe+= string(get_integer(db_column_get_name(table, a),db_column_get_default(table, a)));
		}
	else
		{
		exe+= '"'+get_string(db_column_get_name(table, a),db_column_get_default(table, a))+'"';
		}
	if(a<db_column_count(table)-1)exe+=", ";
	else exe+=")";
}
execute_string(exe);

EDIT: Never mind, they seem to already be in there :)
I think you should make them function-colored or whatever, they're very useful :)

I'm not even gonna bother making a new editor, I'm just going to use yours right now cause it's so user-friendly! THANKS AGAIN!

EDIT2: There seems to be a bug where decimal values won't be saved. :s

Edited by brod, 27 November 2009 - 04:53 AM.

  • 0

#19 benetonmovie

benetonmovie

    GMC Member

  • GMC Member
  • 1368 posts
  • Version:GM:Studio

Posted 27 November 2009 - 05:47 AM

A suggestion, though.
db_column_get_name/type/default()

Hmm, that shouldn't be too hard to add, but I remember deciding not to do it because you're normally supposed to know what they are. I guess if you want to give the user some control on the database structure... but then why do you need that?


EDIT2: There seems to be a bug where decimal values won't be saved. :s

Please tell me how to reproduce the bug! Thanks!

Edited by benetonmovie, 27 November 2009 - 05:53 AM.

  • 0

#20 brod

brod

    Brian RODriguez

  • GMC Member
  • 2021 posts
  • Version:GM8

Posted 27 November 2009 - 05:50 AM

Hmm, that shouldn't be too hard to add, but I remember deciding not to do it because you're normally supposed to know what they are. I guess if you want to give the user some control on the database structure... but then why do you need that?

Well in my case, I'm trying to make a complete engine where I can make tables on the fly using the exe, and not having to go into the gmk changing everything. Also, that code snippet I posted above is a good example on how to achieve that. I'm sure that other people will try to do the same thing, so it wouldn't hurt to add.

Please tell me how to reproduce the bug! Thanks!

I just put a decimal in get_integer(), and for some reason it wouldn't show up on the table.
never mind, I know what I've done wrong.

Edited by brod, 27 November 2009 - 05:56 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users