GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: Script Submission » ds_list_sort_assoc » 2012-10-23 17:21:04

uh? ds_priority_ does not sort two associated lists.

It does, or at least, it does what this script tries to do. If you take the list from OP:

Daniel 200
Xot 100
icuurd 150

You can use the names as values, and the number behind it (the score?) as priority.

#2 Re: Script Submission » ds_list_sort_assoc » 2012-10-13 13:51:25

Even though this topic is more than half a year old, I'll just throw this in here: This already exists - it's called ds_priority_ .

#3 Re: Script Submission » quicksort algorithm » 2011-04-09 13:13:16

Ah, ok..

But what do you think about the script? (A)

#4 Re: Script Submission » quicksort algorithm » 2011-04-05 14:27:32

Expandvar m, M, p, n, t;
m = argument0;
M = argument1;

if m >= M
 {
  return 0;
 }
if (m+1 == M)
 {
  if array[m] > array[M]
   {
    t = array[m];
    array[m] = array[M];
    array[M] = t;
   }
  return 0;
 }

n = (m+M) div 2;
p = array[n];
array[n] = array[M];
array[M] = p;

repeat M-m
 {
  if (array[m] > p) break;
  m += 1;
 }
repeat M-m
 {
  if (array[M] < p) break;
  M -= 1;
 }

while (m < M)
 {
  t = array[m];
  array[m] = array[M];
  array[M] = t;
  repeat M-m
   {
    if (array[m] > p) break;
    m += 1;
   }
  repeat M-m
   {
    if (array[M] < p) break;
    M -= 1;
   }
 } 

array[argument1] = array[m];
array[m] = p;

quicksort(argument0, m-1);
quicksort(m+1, argument1);

EDIT: Eh, your forum acts weird.. It automatically lowercased some M's to m's..(EDIT2: M's with no spaces on both sides, to be precies) Here's a version on pastebin: http://pastebin.com/8zZDT56R

xot wrote:

Replaced your code with the code from pastebin.

#5 Re: Script Submission » quicksort algorithm » 2011-04-05 07:59:21

Here is an updated, working version:

Expandvar m, M, p, n, t;
m = argument0;
M = argument1;

if m >= M
 {
  return 0;
 }
if (m+1 == M)
 {
  if array[m] > array[m]
   {
    t = array[m];
    array[m] = array[m];
    array[m] = t;
   }
  return 0;
 }

n = (m+M) div 2;
p = array[n];
array[n] = array[m];
array[m] = p;

repeat M-m
 {
  if (array[m] > p) break;
  m += 1;
 }
repeat M-m
 {
  if (array[m] < p) break;
  M -= 1;
 }

while (m < M)
 {
  t = array[m];
  array[m] = array[m];
  array[m] = t;
  repeat M-m
   {
    if (array[m] > p) break;
    m += 1;
   }
  repeat M-m
   {
    if (array[m] < p) break;
    M -= 1;
   }
 } 

array[argument1] = array[m];
array[m] = p;

quicksort(argument0, m-1);
quicksort(m+1, argument1);

Should I make variable_global/local_array function? Or is this ok?

#6 Script Submission » quicksort algorithm » 2011-04-04 09:51:03

BlueMoonProductions
Replies: 6

This is a quicksort algorithm I recently wrote. Quicksort is an extremely powerful algorithm to sort arrays.
The script is called using quicksort(min,max), and will sort an array ranging from array[min] to array[max].

Expandvar m, M, p;
m = argument[0]
M = argument[1]

if !(m < M)
 {
  return 0
 }else if (m+1 == M){
  if array[m] > array[m]
   {
    array[m] = array[m] ^ array[m];
    array[m] = array[m] ^ array[m];
    array[m] = array[m] ^ array[m];
   }
  return 0
 }

p = array[ floor( (m+M)/2 ) ]
array[floor( (m+M)/2 )] = array[m]
array[m] = p

while (m < M)
 {
  while ( (array[m] <= p) && (m<M) )
   {
    m += 1
   }

  while ( (array[m] >= p) && (m<M) )
   {
    M -= 1
   }
   
  if (m < M)
   {
    array[m] = array[m] ^ array[m];
    array[m] = array[m] ^ array[m];
    array[m] = array[m] ^ array[m];
   }
 } 

array[m] = p

quicksort(argument[0], m-1)
quicksort(M+1, argument[1])

This algorithm sorts a 6000 field array in 140 miliseconds(on my PC).

#8 Re: Script News & Announcements » Happy (Belated) New Year (Again)! » 2011-02-24 07:55:35

When are you planning to add the scripts that are currently waiting in the 'Script Submissions' board?

#9 Script Submission » draw_reflection » 2011-02-24 07:54:22

BlueMoonProductions
Replies: 2

This is a simple script I recently wrote at request. It can be used to create that Web 2.0 - like reflection:

Expand/*
**  Usage:
**      draw_reflection(source x, source y, source w, source h, target x, target y, target w, target h);
**
**  Arguments:
**      source x, source y, source w, source h: the coordinates of the source, reals
**      target x, target y, target w, target h: the coordinates of the target, reals
**
**  Returns:
**      nothing
**
**  Notes:
**      This script automatically:
**       - Flips the reflection upside-down
**       - Makes the reflection fade away
**
**  GMLscripts.com
*/
var bg, tex;
bg = background_create_from_screen(argument[0],argument[1],argument[2],argument[3],false,false)
tex = background_get_texture(bg)

draw_primitive_begin_texture(pr_trianglefan,tex)
 draw_vertex_texture_color(argument[4],argument[5],0,1,c_white,1)
 draw_vertex_texture_color(argument[4]+argument[6],argument[5],1,1,c_white,1)
 draw_vertex_texture_color(argument[4]+argument[6],argument[5]+argument[7],1,0,c_white,0)
 draw_vertex_texture_color(argument[4],argument[5]+argument[7],0,0,c_white,0)
draw_primitive_end()

background_delete(bg)

An example: http://updo.nl/file/5f42c8b7.gmk

#10 Community » GML Scripts Gex » 2010-11-24 13:41:00

BlueMoonProductions
Replies: 1

Hey,

I was thinking, have you ever considered a GML Scripts GEX? It would be quite useful to have al the scripts built-in, right?

#11 Re: Script Submission » (simple!) collision_triangle » 2010-09-15 04:51:56

Call it limitation, whatever: it is a (small) problem..

I browsed through the topic, but I couldn't find any solutions(right?)..

#12 Re: Script Submission » (simple!) collision_triangle » 2010-09-15 02:39:55

That's true. I rewrote the script, and it can now handle indices instead of id's, and it has the 'notme'-argument. I haven't tested it yet, but i think it's correct:

Expand/// collision_triangle(x1,y1,x2,y2,x3,y3,obj,prec,notme)

var xx, yy, coll_line;

xx[1] = argument[0]
yy[1] = argument[1]
xx[2] = argument[2]
yy[2] = argument[3]
xx[3] = argument[4]
yy[3] = argument[5]

coll_line[1] = collision_line(xx[1],yy[1],xx[2],yy[2],argument[6],argument[7],argument[8])
if (coll_line[1]!=noone) then return coll_line[1]

coll_line[2] = collision_line(xx[2],yy[2],xx[3],yy[3],argument[6],argument[7],argument[8])
if (coll_line[2]!=noone) then return coll_line[2]

coll_line[3] = collision_line(xx[3],yy[3],xx[1],yy[1],argument[6],argument[7],argument[8])
if (coll_line[3]!=noone) then return coll_line[3]

with (argument[6])
 {
  if (point_in_triangle(xx[1],yy[1],xx[2],yy[2],xx[3],yy[3],x,y) && argument[8]!=id)
   return id
 }break

return noone

Oh, and does anyone have an idea how to fix the origin-should-be-on-sprite bug? sad

#13 Script Submission » (simple!) collision_triangle » 2010-09-14 11:04:50

BlueMoonProductions
Replies: 5

Hey,

A few days ago I wrote a simple collision_triangle script.

You can download the example(including the scripts) here: http://easy-upload.nl/f/rOYFPBma (gm8) (use mouse to move the object, space to generate random triangle coords)
(EDIT in the collision_triangle script, you can remove the variabele 'i' in var ... ; /EDIT)

This is the syntaxis:

Expandcollision_triangle(x1,y1,x2,y2,x3,y3,obj,prec)

x1 .. y3 are the triangle-coordinates.
obj is the object to check, this is an id, not an index!! It's not hard to rewrite the script to an index-compitable-version.
prec: the same as the build-in collision_ functions.

One important thing, the sprite's origin, must be located on the sprite's bounding box itself, and if the precise-argument is true, on the sprite itself. So:
YSH56R6r
You won't get any errors if you didn't do this, but the script may return the wrong value.

The script uses point_in_triangle (in the GMK you can also find 'is_clockwise', but you don't need that one).
It's not perfect, but way faster than the current collision_triangle. Maybe you could add this one as 'collision_triangle_simple'?

Blue

#14 Re: Script Submission » Some of my 3d Scripts » 2010-08-30 02:24:36

xot wrote:

Damn, your computer is fast!

New computer biggrin
It's just a few weeks old, no junk on it yet tongue

#16 Re: Script Submission » Some of my 3d Scripts » 2010-08-27 04:29:55

Hm, never thought about that..

Well, with 'place them together' I don't necessarily mean one page, but you should at least make clear that the scripts should be used together.

#17 Re: Script Submission » Some of my 3d Scripts » 2010-08-26 13:54:11

Okay, and 'some other 3d scripts':

Maybe you know some people use lengthdir_y as lengthdir_z script. Well, that doesn't work when using it in combination with lengthdir_x and -y for the x and y coordinates.
That's because lengthdir_x and -y use the 'yaw'(: direction), and pitch is an important factor as well.

I hope this image explains what I mean:

EDIT: z-factor should be z-vector xD
hVk71bHV

(it's very hard for me to explain this because i'm Dutch tongue)

As you can see, the length of the 3D-vector(Color: bordeaux, bold) is the same as the 2D-vector which only uses lengthdir_x and -_y. If you now use lengthdir_y as -_z, the 'position' of the end of the vector, will be at the end of the 2D vector (which uses _x and _y), and the z-position it should have.

I hope you understand what i'm trying to say, lengthdir_x and -_y aren't affected by the pitch. These lengthdir_x/-_y (and _z) scripts do this correctly:"

lengthdir_x_3d:

Expand// lengthdir_x_3d(len,yaw,pitch)
// yaw = direction

return argument0*(cos(degtorad(argument1))*cos(degtorad(argument2)));

lengthdir_y_3d:

Expand// lengthdir_y_3d(len,yaw,pitch)
// yaw = direction

return argument0*(-sin(degtorad(argument1))*cos(degtorad(argument2)));

lengthdir_z_3d:

Expand// lengthdir_z_3d(len,pitch)
// pitch only!!

return argument0*(sin(degtorad(argument1)));

You should place the scripts together (not all 3 as seperate scripts), there very usefull.

#18 Re: Script Submission » Some of my 3d Scripts » 2010-08-26 11:24:47

Yes, but I think it's still good to make that clear, because it's not a build-in. And some people only use zmin and zmax.

#19 Re: Script Submission » Some of my 3d Scripts » 2010-08-26 03:34:27

Thank you smile
I'm new here, if you are going to add them, when?

#20 Script Submission » irandom_range_gm7 » 2010-08-25 14:22:55

BlueMoonProductions
Replies: 1

Hey,

In GM8 there is a function called irandom_range. This returns an integer(!) between argument0 and argument1. This (very small) script is exactly the same, so you can use it in GM7< as well:

Expandreturn floor(random(argument1-argument0+1))+argument0;

Board footer

Powered by FluxBB