GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: Game Maker Bugs » draw_line_width_color - confirmed BUG in GM7 » 2008-05-21 02:07:29

So I got the "unexpected error" thing when in the draw event, like you said. I then tried it in a keyboard event, and it locked up the program. Task Manager said I was using about 52% of CPU power, but that's likely due to having a dual core processor. I was able to close the program without a reboot, but there is definitely issues with that function.

(Intel Core 2 CPU, 1.6 GHz, Windows Vista Home Premium, 2 GB RAM)

#2 Re: Off Topic » Behold the math » 2008-04-26 14:10:53

Very impressive! You're studying engineering at U of I, am I right? I'm also studying engineering (at Purdue), but I've barely begun.
I'm not bad at math, but it looks like I'll need to brush up on it if I'm to keep up!

#3 Re: Script Submission » Drawing Sprites Centered Script » 2008-03-31 19:07:36

I thought that giving the x or y value would be more useful. It could be stored in a variable and used to draw multiple things (such as centering several equal-sized buttons).
I've taken your 3rd and 4th suggestions, though:

Expand/*
**      center_sprite(1,sprite0,0,room_width);
**
**      argument0 = true for horizontal (x value), false for vertical (y)
**      argument1 = sprite name
**      argument2 = true for centering the sprite origin, false for centering absolutely
**      argument3 = width or height to center in
**
**      Returns the x or y value at which to draw the sprite so that
**                  it is centered in the given distance
*/
var val;
if (argument0) {
    if (argument2) val=argument3 div 2 else val=(argument3-sprite_get_width(argument1)) div 2+sprite_get_xoffset(argument1);
} else {
    if (argument2) val=argument3 div 2 else val=(argument3-sprite_get_height(argument1)) div 2+sprite_get_yoffset(argument1);
}
return val;

EDIT: please pardon the forced line breaks biggrin

#4 Script Submission » Drawing Sprites Centered Script » 2008-03-30 23:21:22

RoboBOT
Replies: 2

Here is a simple script to find the x and y values at which a sprite should be drawn so that it is centered in the room. This is good for title screens, etc.
One can input either the sprite name or the width (or height).
To find the x value:

Expand/*
**      sprite_centered_x(spr);
**
**      argument0 = either a sprite name or an integer referring
**                  to the width of the thing to be centered
**
**      Returns the x value at which to draw the sprite so that
**                  it is centered in the room
*/
var xx;
if (sprite_exists(argument0)) {
    xx=(room_width-sprite_get_width(argument0)) div 2+sprite_get_xoffset(argument0);
} else {
    xx=(room_width-argument0) div 2;
}
return xx;

To find the y value:

Expand/*
**      sprite_centered_y(spr);
**
**      argument0 = either a sprite name or an integer referring
**                  to the height of the thing to be centered
**
**      Returns the y value at which to draw the sprite so that
**                  it is centered in the room
*/
var yy;
if (sprite_exists(argument0)) {
    yy=(room_height-sprite_get_height(argument0)) div 2+sprite_get_yoffset(argument0);
} else {
    yy=(room_height-argument0) div 2;
}
return yy;

EDIT: After thinking a bit, I think having a second argument giving the width to be centered in would be useful. Then you could center it in the room, the view, or in any specific area by doing something like: x=room_width-235+sprite_centered_x(sprite0,235)  //center sprite0 in the area 235 pixels wide at the right
Thoughts?

#5 Re: Script Submission » Euler's Totient Script » 2008-02-24 19:15:50

Yeah, I see the problems with my variable declarations. You mean I didn't declare et in the first script and declared c instead of et in the second, right? I fixed those.

Oh, and I'll remove the extraneous semicolons, if you prefer.

#6 Script Submission » Euler's Totient Script » 2008-02-24 14:50:22

RoboBOT
Replies: 4

Hello all! I'd thought I'd contribute a script.
Euler's totient is the number of integers that are less than the value and coprime (no common factors).
It's useful in pseudorandom number generators, for example. I admit though, it's uses for the average game maker are limited.

I have two versions, but I'm pretty sure the first version listed is a lot faster:
Version 1:

Expand/*
**      eulers_totient(number);
**
**      argument0 = a postive real number
**
**  Returns the value of Euler's totient as a real number
**
**  Notes:
**      Euler's totient is how many coprime numbers there are
**      less than the inputted number.
**      Uses the function "factor(n)"
*/

var f,i,val,val_prev,et;
et=argument0;
val_prev=0;
f=factor(argument0);
ds_list_sort(f,true);
for (i=0;i<ds_list_size(f);i+=1) {
    val=ds_list_find_value(f,i);
    if (val!=val_prev) et*=(1-(1/val));
    val_prev=val;
}
ds_list_destroy(f);
return et;

Version 2:

Expand/*
**      eulers_totient(number);
**
**      argument0 = a postive real number
**
**  Returns the value of Euler's totient as a real number
**
**  Notes:
**      Euler's totient is how many coprime numbers there are
**      less than the inputted number.
**      Uses the function "gcd(n)"
*/
var i,et;
i=1;
et=0;
while (i<argument0) {
    if (gcd(i,argument0)=1) et+=1;
    i+=1;
}
return et;

By the way, if we donate a script to GMLscripts, may we also post the script on our own website? (Though I don't mean this script, since I made use of scripts from this site)

Board footer

Powered by FluxBB