You are not logged in.
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.
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_ .
Ah, ok..
But what do you think about the script? (A)
var 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
Replaced your code with the code from pastebin.
Here is an updated, working version:
var 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?
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].
var 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).
I'll write a more usable script soon
When are you planning to add the scripts that are currently waiting in the 'Script Submissions' board?
This is a simple script I recently wrote at request. It can be used to create that Web 2.0 - like reflection:
/*
** 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
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?
Call it limitation, whatever: it is a (small) problem..
I browsed through the topic, but I couldn't find any solutions(right?)..
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:
/// 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?
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:
collision_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:
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
Damn, your computer is fast!
New computer
It's just a few weeks old, no junk on it yet
Okay.. My results:
4103 3385 2667
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.
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
(it's very hard for me to explain this because i'm Dutch )
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:
// lengthdir_x_3d(len,yaw,pitch)
// yaw = direction
return argument0*(cos(degtorad(argument1))*cos(degtorad(argument2)));
lengthdir_y_3d:
// lengthdir_y_3d(len,yaw,pitch)
// yaw = direction
return argument0*(-sin(degtorad(argument1))*cos(degtorad(argument2)));
lengthdir_z_3d:
// 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.
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.
Thank you
I'm new here, if you are going to add them, when?
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:
return floor(random(argument1-argument0+1))+argument0;