GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: Script Submission » file_find_list » 2008-03-24 17:49:01

The big chuck was indeed written by torigara. I was heading towards PMing him/her for a submission here, when I finally decided to make some modifications. But they're minor, so I'd rather see torigara in the credits than my name.

#2 Script Submission » file_find_list » 2008-03-24 13:26:16

Quimp
Replies: 6

I came across this set of scripts. The scr_find_files() looks fantastic: http://gmc.yoyogames.com/index.php?showtopic=256775

I adapted the script so it creates the list automatically instead of using a user-provided one, I made it possible to search for more than one extension at a time and finally I added an argument to search through subdirectories.

Expand// This script searches all files under the specified directory.
// file_find_list(root, extensions, subdir);
// returns a list data structure containing the full path of the files found
// my_list = file_find_list("C:\Windows", ".jpg|.gif|.bmp", true);

var list, subdir_queue, file_name, dir_name, full_path;

list = ds_list_create();
subdir_queue = ds_queue_create();
ds_queue_enqueue(subdir_queue, argument0);
argument1 = "|" + argument1 + "|";

while (!ds_queue_empty(subdir_queue))
 {
  dir_name = ds_queue_dequeue(subdir_queue);
  file_name = file_find_first(dir_name + '\*', fa_directory);

  while (file_name != '')
   {
    full_path = dir_name + '\' + file_name;
    
    if (file_attributes(full_path, fa_directory) && argument2)
     {
      if (file_name != '.' && file_name != '..')
       {
        ds_queue_enqueue(subdir_queue, full_path);
       }
     }
    else
     {
      if (string_pos("|" + string_lower(filename_ext(file_name)) + "|", argument1) > 0)
       {
        ds_list_add(list, full_path);
       }
     }
    file_name = file_find_next();
   }
  file_find_close();
 }

ds_queue_destroy(subdir_queue);
return (list);

A quick test (don't forget to destroy the list) :

Expandlist = file_find_list(get_directory(''), get_string("File extension :", ".jpg|.gif|.bmp"), true);
Expandvar i;
for (i=0; i<ds_list_size(list); i+=1)
 {
  draw_text(50, 50 + 30*i, ds_list_find_value(list, i));
 }

The script would probably be faster if instead of delimiting the extensions the script asked for an array (for loop comparison) or a list (ds_list_find_index > -1). Have your say!

Cheers,
Quimp

#3 Re: GML Reference » return - unexpected behavior » 2008-03-09 02:40:34

A striking result. I was well aware that functions need to return a value, hence why the "return" keyword is sometimes unnecessary (bad programming practice) but I didn't know the returned value could have anything to do with assignments from a source outside a script. Ughh, indeed a weird behavior.

#4 Re: GML Code Help » A question of style: arguments » 2008-02-06 18:31:48

I believe I'm on the same boat as Yourself. If I pass an array to a script in the form of a string, and as a feature I let the user specify whether the array is global or not. I will then remove the "global." part of THE argument and trigger a boolean variable for calls to global or local functions (variable_array_* or whatever they are).

#5 Re: Script Alumni » turn_toward_direction - overhaul » 2008-01-24 23:06:06

In a top-down shooter, for example, the player could be set to face the mouse and still not go in that particular direction (he could be walking backwards). But in general, I agree that the image_angle = direction; part is useful. You almost expect the script to do it for you just by looking at its name.

While Game Maker uses "toward" at some places in the help file, it seems that all functions or actions use the form with a S. For example, move_towards_point() comes to mind. For more clarification, here's a quote from The Free Dictionary:

http://www.thefreedictionary.com/toward wrote:

Some critics have tried to discern a semantic distinction between toward and towards, but the difference is entirely dialectal. Toward is more common in American English; towards is the predominant form in British English.

Since we're on the subject, you may want to fix the second argument on Smarty's code. Whether it really is 'turnrate' or 'step', there is an extra apostrophe in the description of that argument :

**      turn_towards_instance(instance,turnrate);
**
**  Arguments:
**      instance    An object or instance ID to turn to (argument0)
**      step          Step size or 'turn 'speed', degrees (argument1)

- Quimp

#6 Re: Off Topic » Preposterous Code » 2008-01-11 00:33:03

bonus #2 wrote:

Wow... you are right... though, i tested the script and it worked fine until you told me that it didnt work, and i tested it again, and it didnt work...

#7 Re: GML Reference » Undocumented string features » 2007-12-17 11:52:16

If it's an online game, perhaps it happened in a PHP file (for example), where if (a = b) checks if setting a to b worked (true).

#8 Re: Script Submission » ds_list extensions » 2007-11-19 20:00:46

It was not my intention to resubmit some of the scripts, I missed this update. (I see that you added visuals to some scripts, that's brilliant). I like the fact that some of my scripts use an optional argument for sample populations rather than having separated scripts though.

#9 Script Submission » ds_list extensions » 2007-11-18 22:56:20

Quimp
Replies: 5

I wrote a few scripts to extend the list data structure functions. I avoided relying on other scripts, so it may be a bit redundant (ex.: standard_deviation = sqrt(ds_list_variance(list)); )

Expand/*
ds_list_mean(list)

Arguments:
    list (real) - List data structure

Returns: (real)
    the arithmetic mean of the list's values
*/

var n, avg, i;
n = ds_list_size(argument0);
avg = 0;

for (i=0; i<n; i+=1)
 {
  avg += ds_list_find_value(argument0, i);
 }

return avg/n;
Expand/*
ds_list_variance(list[, sample])

Arguments:
    list (real) - List data structure
    sample (optional, bool) - TRUE if the list is made up of a sample

Returns: (real)
    the variance of the given list
*/


var n, avg, sum, i;
n = ds_list_size(argument0);
avg = 0;
sum = 0;

for (i=0; i<n; i+=1)
 {
  avg += ds_list_find_value(argument0, i);
 }

avg /= n;

for (i=0; i<n; i+=1)
 {
  sum += sqr(ds_list_find_value(argument0, i) - avg);
 }

return sum/(n - argument1);
Expand/*
ds_list_vrm(list[, sample])

Arguments:
    list (real) - List data structure
    sample (optional, bool) - TRUE if the list is made up of a sample

Returns: (real)
    the variance-to-mean ratio (V.R.M.) of the given list
*/

var n, avg, sum, i;
n = ds_list_size(argument0);
avg = 0;
sum = 0;

for (i=0; i<n; i+=1)
 {
  avg += ds_list_find_value(argument0, i);
 }

avg /= n;

for (i=0; i<n; i+=1)
 {
  sum += sqr(ds_list_find_value(argument0, i) - avg);
 }

return sum/(n - argument1)/avg;
Expand/*
ds_list_stand_deviation(list[, sample])

Arguments:
    list (real) - List data structure
    sample (optional, bool) - TRUE if the list is made up of a sample

Returns: (real)
    the standard deviation of the given list
*/

var n, avg, sum, i;
n = ds_list_size(argument0);
avg = 0;
sum = 0;

for (i=0; i<n; i+=1)
 {
  avg += ds_list_find_value(argument0, i);
 }

avg /= n;

for (i=0; i<n; i+=1)
 {
  sum += sqr(ds_list_find_value(argument0, i) - avg);
 }

return sqrt(sum/(n - argument1));
Expand/*
ds_list_cv(list[, sample])

Arguments:
    list (real) - List data structure
    sample (optional, bool) - TRUE if the list is made up of a sample

Returns: (real)
    the coefficient of deviation (C.V.) of the given list
*/

var n, avg, sum, i;
n = ds_list_size(argument0);
avg = 0;
sum = 0;

for (i=0; i<n; i+=1)
 {
  avg += ds_list_find_value(argument0, i);
 }

avg /= n;

for (i=0; i<n; i+=1)
 {
  sum += sqr(ds_list_find_value(argument0, i) - avg);
 }

return sqrt(sum/(n - argument1))/avg;

I'm not sure about this one. How do you call it in English? In French it's called the "Cote Z".

Expand/*
ds_list_z_cote(list, pos)

Arguments:
    list (real) - List data structure
    pos (real) - The position in the list 

Returns: (real)
    the z cote of the value at position pos in the given list
*/

var n, avg, sum, i;
n = ds_list_size(argument0);
avg = 0;
sum = 0;

for (i=0; i<n; i+=1)
 {
  avg += ds_list_find_value(argument0, i);
 }

avg /= n;

for (i=0; i<n; i+=1)
 {
  sum += sqr(ds_list_find_value(argument0, i) - avg);
 }

return (ds_list_find_value(argument0, argument1) - avg)/sqrt(sum/n);
Expand/*
ds_list_dispersion(list)

Arguments:
    list (real) - List data structure

Returns: (real)
    the dispersion of the given list
*/

var n, maxv, minv, i, val;
n = ds_list_size(argument0);
maxv = ds_list_find_value(argument0, 0);
minv = maxv;

for (i=1; i<n; i+=1)
 {
  val = ds_list_find_value(argument0, i);
  
  if (val > maxv)
   maxv = val;
  else if (val < minv)
   minv = val;
 }

return (maxv - minv);
Expand/*
ds_list_max(list)

Arguments:
    list (real) - List data structure

Returns: (real)
    the maximum value of the given list
*/

var n, maxv, i, val;
n = ds_list_size(argument0);
maxv = ds_list_find_value(argument0, 0);

for (i=1; i<n; i+=1)
 {
  val = ds_list_find_value(argument0, i);
  
  if (val > maxv)
   maxv = val;
 }

return maxv;
Expand/*
ds_list_min(list)

Arguments:
    list (real) - List data structure

Returns: (real)
    the minimum value of the given list
*/

var n, minv, i, val;
n = ds_list_size(argument0);
minv = ds_list_find_value(argument0, 0);

for (i=1; i<n; i+=1)
 {
  val = ds_list_find_value(argument0, i);
  
  if (val < minv)
   minv = val;
 }

return minv;

And somewhat lost in the bunch is...

Expand/*
ds_list_geometric_mean(list)

Arguments:
    list (real) - List data structure

Returns: (real)
    the geometric mean of the list's values
*/

var n, geo, i;
n = ds_list_size(argument0);
geo = 1;

for (i=0; i<n; i+=1)
 {
  geo *= ds_list_find_value(argument0, i);
 }

return power(geo, 1/n);

I also wrote one for the Harmonic Mean but somehow I lost it. If you think it could be useful, it will take only a few seconds to write.

Edit: Oh boy! I totally forgot to adapt the scripts to your style. I'm not even sure the header is correct either. I may do it later, but not today.

Cheers!
Quimp

#10 Re: Script Alumni » draw_sprite_tiled_area[_ext] - slight improvement » 2007-11-14 14:08:02

**  Notes:
**      x1 MUST be less than x2, and y1 less than y2
**      (x,y) doesn't have to be in the area, but if it is, then some
**          drawn sprite will have it's origin at this point

You mean its, not "it is" shortened as it's.

#11 Re: Script Submission » ROT13 Encryption » 2007-11-07 00:17:59

I agree about the argument "a", it could lead to confusion. Other than that, you could remove the string_length() function from the loop to make it faster but I don't know how much it could affect speed.

#12 Re: Script News & Announcements » Mathematical Expressions » 2007-10-19 18:23:33

If you need help with some of the French to figure out how things work, I'll be glad to help you out. I installed the application on my server (for personal use) and I agree that it's poorly written.

In any case, thanks for sharing your finding.

Board footer

Powered by FluxBB