GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#2 Re: GML Reference » image_index is a decimal » 2010-01-06 09:26:09

Yes, but many newer users get confused if trying to cut an animation short with "if(image_index == whatever)".

Testing for image_index == 3 fails. floor(image_index) == 3 works fine.

EDIT: This is related to the confusing fact that score is a signed integer.

#3 GML Reference » image_index is a decimal » 2010-01-03 06:26:17

PlasticineGuy
Replies: 6

This appears to be present in at least GM7 and GM8, though most likely earlier.
Unexpectedly, image_index is a floating-point decimal. This can make debugging a nightmare, as I found out. You cannot directly test image_index == value; instead you must use floor(image_index) == value. The help file states that it can have a fractional part, but it fails to mention that unless image_speed also does not have a fractional part, image_index will be expressed as a floating-point decimal.

#4 Script Submission » Encrypt/decrypt string and file script » 2009-12-12 06:11:17

PlasticineGuy
Replies: 3
Expand/*
** Usage:
**     my_str = crypt(str)
**
** Arguments:
**     str        String to encrypt, string
**
** Returns:
**     my_str     Result of encryption, string
**
** Notes:
**     This script works for both encryption and decryption.
**
** GMLscripts.com
*/
{
    var str, str2, i;
    str = argument0;
    str2 = '';
    for(i = 1; i <= string_length(str); i += 1) {
        str2 += chr(~ord(string_char_at(str, i)));
    }
    return str2;
}

The above is a simple encryption script using the bitwise NOT operator designed to be easy to use but effective.
Input: PlasticineGuy
Output: ¯“žŒ‹–œ–‘š¸Š†

I have also designed a file encryption script:

Expand/*
** Usage:
**     file_crypt(file)
**
** Arguments:
**     file       String to encrypt, file ID
**
** Returns:
**     1          Returns a value to avoid odd behaviour described by Xot.
**
** Notes:
**     This script works for both encryption and decryption.
**
** GMLscripts.com
*/
{
    var buffer, buffer2, fp, fn, i;
    buffer = "";
    buffer2 = "";
    fn = argument0;
    fp = file_bin_open(fn, 2);
    while(file_bin_position(fp) != file_bin_size(fp)){
        buffer += chr(file_bin_read_byte(fp));
    }
    file_bin_close(fp);
    for(i = 1; i <= string_length(buffer); i += 1) {
        buffer2 += chr(~ord(string_char_at(buffer, i)));
    }
    fp = file_text_open_write(fn);
    file_text_write_string(fp, buffer2);
    file_text_close(fp);
    return 1;
}

EDIT: Fixed to follow specification.

Board footer

Powered by FluxBB