GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#2 Re: Script Submission » Decimal to Fraction Script » 2009-06-26 05:34:54

pow = string_length(string_digits(frac(number)))

There's nothing in that line that turns number into a string.  It'd also probably be faster and more accurate to multiply by 2 (and by more accurate I mean the rational result will be exact insofar as the double data type is concerned).

#3 Re: Off Topic » IGF 2009 Finalists Announced » 2009-01-09 02:26:29

I don't get it.  Is Blueberry Garden actually finished, or are they just giving away awards based on videos of games?

#4 Re: Script Submission » Euler's Totient Script » 2008-09-23 02:10:29

I guess I missed seeing this.  This script could actually be used to reduce large powers of some number module another.  Euler's theorem states the following:

a^phi(m) === 1 (mod m)

if GCD(a, m) = 1.

That is, a to the phi(m) is congruent to 1 (mod m) where phi is Euler's totient function.  For example:

Find the last two digits of 3^39 in base 10.  Well, phi(100) = 40, so 3^40 === 1 (mod 100), so 3^-1 * 3^40 === 3^-1 (mod 100).  So, we need only find the multiplicative inverse of 3 mod 100.  3*33 === -1 (mod 100) => 3*(-33) === 1 (mod 100) => 3*67 === 1 (mod 100), so the last two digits of 3^39 are 67.

Similarly the last two digits of the following are:

3^40 = 01
3^41 = 03
3^42 = 09...

#5 Re: Script Submission » ds_list_append_list » 2008-07-16 10:28:07

Yes, both a real and a string can be stored in a record simultaneously.  However, I don't know why that's useful since you'd only be able to access one from GM.  Additionally, the type identifier might cause it to only load the correct type and just ignore the other.

One thing you could do is transform a bunch of lists into a grid or vice-versa where each list is a column.  It also allows you to quickly slice lists and change them between stacks and queues.  However, I think some people used that trick a long time ago (but just supplying the entire string into the read function of a different data structure, rather than reformatting it).

#6 Re: Script Submission » ds_list_append_list » 2008-07-15 16:23:59

It's almost a straight memory dump but in hex.  Here's a little text file I cooked up back when I decided to figure the format out for use from a DLL.  It's quite a verbose format, which is why I'd prefer base 64.

All of GM's data structure's seem to output what is essentially a hex encoded memory dump of the
data structure.  This means that all integers and doubles are encoded in little-endian format.

---------------------------------------------------------------------------------------------------
list, stack, queue:
Offset      Size (b)    Information
0x00        4           DS identifier (see below)
0x04        4           (int) number of elements in structure
Element record
{
    0x00    4       Indicates whether element is a string (1) or real (0)
    0x04    8       IEEE 754 double
    0x0C    4       (int) Length of following string field (0 if not present)
   [0x10    (0x0C)  bytes contained in string (only present if previous field != 0)]
}
---------------------------------------------------------------------------------------------------
map, pqueue:
Offset      Size (b)    Information
0x00        4           DS identifier (see below)
0x04        4           (int) number of elements in structure
Key/Priority record
{
    0x00    4       Indicates whether element is a string (1) or real (0)
    0x04    8       IEEE 754 double
    0x0C    4       (int) Length of following string field (0 if not present)
   [0x10    (0x0C)  bytes contained in string (only present if previous field != 0)]
}
Value record
{
    Same as above
}

Maps store their keys in order first.  Then the values are recorded in order.  For keys, real
values come before strings.  Priority queues are similar in that the priorities are stored before
their associated values, however the priorities are unsorted and show up in the order that they
were added to the queue.
---------------------------------------------------------------------------------------------------
grid:
Offset      Size (b)    Information
0x00        4           (0x59020000)
0x04        4           (int) width
0x08        4           (int) height
Element record
{
    0x00    4       Indicates whether element is a string (1) or real (0)
    0x04    8       IEEE 754 double
    0x0C    4       (int) Length of following string field (0 if not present)
   [0x10    (0x0C)  bytes contained in string (only present if previous field != 0)]
}

Elements are stored in column-major order.

===================================================================================================

Identifers:
list:   0x2D010000
stack:  0x65000000
queue:  0xC9000000

map:    0x91010000
pqueue: 0xF5010000

grid:   0x59020000

#7 Re: Script Submission » ds_list_append_list » 2008-07-15 01:46:13

No, I haven't tested its speed at all.  I don't know what you mean about accuracy, though.  This won't lose any accuracy.

I really wish GM used Base64 instead of Hexadecimal for these strings, though.  Hexadecimal is too big.

#9 Script Submission » ds_list_append_list » 2008-07-13 00:49:44

Yourself
Replies: 8
Expand{
    var l1, l2, s1, s2, sr, n, hex;
    hex = "0123456789ABCDEF";
    l1 = argument0; l2 = argument1;
    s1 = ds_list_write(l1); s2 = ds_list_write(l2);
    sr = string_copy(s1, 1, 8);
    n = ds_list_size(l1) + ds_list_size(l2);
    repeat (4) {
        sr += string_copy(hex, ((n & $f0) >> 4) + 1, 1)
           +  string_copy(hex, (n & $0f) + 1, 1);
        n = n >> 8;
    }
    sr += string_delete(s1, 1, 16) + string_delete(s2, 1, 16);
    ds_list_read(l1, sr);
    return l1;
}

Takes two lists as arguments and appends the contents of the second list to the first.

#10 Re: Off Topic » Behold the math » 2008-04-25 00:08:58

I created that in Mathematica.  Whenever you see diagrams, they were created with Mathematica.  They're also rarely schematic diagrams, either.  For example, that diagram actually has the exact lens solution for an index of refraction of (I think) 1.5.

#11 Re: Off Topic » Behold the math » 2008-04-24 14:33:07

Yes, that's the system I'm using.  The system does cache the images as well.

My server already had dvips and such installed, I just had to install the PHP scripts and such for the editor and renderer.

I still haven't integrated it to the extent that I want to.  I'd like to be able to use a WYSIWYG editor with an equation button.  Behind the scenes I have an FCK Editor plugin for Wordpress installed, but getting all this to work is kind of a headache.  Ultimately I think I'd like a little WYSIWYG editor for the comments as well so people can do their own equations.

#14 Re: GML Reference » return - unexpected behavior » 2008-03-08 13:08:04

Keep in mind GM is for beginners.

What does that have to do with anything?  You don't have to make a bad language to make one that's easy to learn or use.  Python is a clear example of this.  It's easy to learn and use but still very powerful.

It's like hating playdough for not being as good as proper modeling plasticine.

What a stupid analogy.  Both substances are meant for completely different purposes and have little in common with a programming language.  Do beginning sculptors use play-doh?  No.  Besides, play-doh doesn't have any real shortcomings.  It does exactly what it's meant to do and it does it very well.  GML does what it was meant to do, but it doesn't do it well.  Big difference.

Have you ever fooled with PyGame?

I've looked at it, but never actually done anything with it.

#15 Re: GML Reference » return - unexpected behavior » 2008-03-08 02:31:07

I hate GML.  As a language it's just very poor.  If GM just used Python...

#16 Re: GML Code Help » BMP Format » 2008-02-23 22:33:07

repeat(4)
    width+=file_bin_read_byte(file);

For one, that's not how little-endian 32-bit integers work.  You can't just add the byte values together.  Just like how 1111 doesn't have the value "4".  You're completely ignoring place value.

#17 Re: Script Submission » Is_Prime » 2008-02-13 02:33:38

This would be much faster:

Expandvar a, p, m;
a[1] = 2; a[3] = 4; a[5] = 2; a[7] = 2; a[9] = 2;
if (argument0 mod 2 == 0) return false;
if (argument0 mod 3 == 0) return false;
p = 5;
m = sqrt(argument0);
while (p < m) {
    if (argument0 mod p == 0) return false;
    p += a[p mod 10];
}
return true;

#18 Re: Script Alumni » gauss - The pseudo-Gaussian » 2008-02-08 01:20:39

That's why it's only an approximation.  It doesn't share the same properties (or the same kind of flexibility) as an actual Gaussian distribution.

#19 Re: Off Topic » Yourself strikes again. » 2008-02-08 01:08:14

That one took me a few minutes to come up with.  I had to recover from being stunned first.

#20 Re: Script Alumni » gauss - The pseudo-Gaussian » 2008-02-06 19:24:15

the sum of N identically independentally distributed random variables, subtract the mean from each

By definition of the mean that sum would be 0.

Board footer

Powered by FluxBB