GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: Script Submission » draw_collision_mask() » 2023-03-09 19:00:03

For sure it doesn't as draw_rectangle doesn't draws rotated rectangles.

#2 Re: Script Submission » Check if running on steamdeck » 2023-03-09 18:50:52

For linux version, for sure this works:

Expandfunction is_deck(){
	var os = os_get_info();
	var _is_deck = false;
	if (os_type == os_linux) {
		if (ds_exists(os, ds_type_map)) {
			var _renderer_info = os[? "gl_renderer_string"];
			if ((_renderer_info != undefined) and string_pos("valve", _renderer_info) > 1 and string_pos("neptune", _renderer_info) > 1) {
				_is_deck = true;
			}
		}
	}
	ds_map_destroy(os);
	return _is_deck;
}

#3 Re: Script Submission » draw_sprite_animated » 2023-03-09 18:48:21

Shouldn't it also take "sprite_get_speed_type" into account?

#4 Re: Script Submission » Script Submission Rules » 2022-10-25 19:24:19

I believe that script style guide could be updated smile

#5 Script Submission » array_create_2d (2022.11+) » 2022-10-24 13:34:05

gnysek
Replies: 0
Expand/// @param {Real} rows
/// @param {Real} cols
/// @param {Any*} value Default value
/// @returns {Array<Array<Any*>>)
function array_create_2d(rows, cols, value) {
    return array_create_ext(rows, method({c: cols, v: value}, function() {
        return array_create(c, v);
    }));
}

#6 Script Submission » array_sum [2022.11+] » 2022-10-20 18:10:11

gnysek
Replies: 0
Expand/// @desc returns sum of elements in array
/// @param {Array} a
function array_sum(a) {
	return array_reduce(a, function(p, v, i) {return p+v;});
}

example:

Expandarray_test = [10, 20, 70];
show_debug_message(array_sum(array_test));
// returns 10+20+70 = 100

#7 Script Submission » array_shuffle » 2022-09-23 04:40:38

gnysek
Replies: 0
Expand/// @param {array} a
/// @returns {undefined}
function array_shuffle(a) {
	/// @returns {real}
	static _shuffle = function() {return choose(1, -1);}
	array_sort(a, _shuffle);
}

usage:

Expandvar a = [1, 2, 3, 4, 5, 6];
array_shuffle(a);
show_debug_message(a); // for example: [ 5,2,1,4,3,6 ]

#8 Re: Script Submission » Is_Prime » 2022-09-20 12:24:22

So, for 2022, most up-to-date version (including <= fix) will be:

Expand/// @param {real} n number to check
/// @returns {bool}
function is_prime(n) {
    var a = [0, 2, 0, 4, 0, 2, 0, 2, 0, 2], p, m;
    if (n mod 2 == 0) return false;
    if (n mod 3 == 0) return false;
    p = 5;
    m = sqrt(n);
    while (p <= m) {
    if (n mod p == 0) return false;
        p += a[p mod 10];
    }
    return true;
}

??

#9 Re: Script Submission » Draw a bent sprite » 2022-06-27 04:42:12

This is genius! I wanted to buy Spine for $330 to apply similar effect in my game for trees, and here I've got same thing for free (and probably faster, as it's doesn't need to process thousands of additional variables).

#10 Re: Script Submission » Foreach [v3.0.1] » 2022-06-27 04:37:37

Main issue with this script is that it uses macros to make some tricks with GML, and replace things on compiling game. While this is OK for very advanced programmers, I think it's not a style that should be promoted for clean code.

#11 Re: Script Submission » is_int » 2022-06-27 04:33:19

Yes, it would be faster.
I've made additional tests on numbers which are shown as 1.00 by show_debug_message or draw_text, but are "0.99999999999998" when using string_format(), and it gives same results in every case.

#12 Script Submission » is_int » 2022-04-01 08:39:46

gnysek
Replies: 2

Edit: updated with faster version by @maras:

Expandfunction is_int(number) {
    return floor(number) == number;
}

Old, less efficient version:

Expandfunction is_int(number) {
    return sign(frac(number)) == 0;
}

Results for both:

Expandshow_debug_message(is_int(1)); // 1
show_debug_message(is_int(1.0)); // 1
show_debug_message(is_int(1.1)); // 0
show_debug_message(is_int(-1)); // 1
show_debug_message(is_int(-1.0)); // 1
show_debug_message(is_int(-1.1)); // 0
show_debug_message(is_int(0)); // 1

#13 Re: Script Submission » Draw point of specified size » 2021-02-16 09:39:20

Issue with this is that depending of GPU (Intel/GeForce/AMD) rectangle might be offset by 1px, and when you use odd number, you have no idea on which pixel it will be rounded in this case. So, the result might be even ~2px wrong.

#14 Community » GMS 2.3.x compatibility ? » 2020-09-08 16:29:25

gnysek
Replies: 3

Hi @xot, are you planning to update website, so people can choose between displaying scripts in 2.3 format (by default; function + JSDOC) and "legacy" (GM8 - 2.2.x) as alternative (maybe using tabs ?).

#15 Re: Script Submission » Get the diagonal screen size in inches » 2020-09-01 05:12:48

Of course not. I was rather thinking about covering all possibilities, but then script will be much bigger.

#16 Re: Script Submission » Get the diagonal screen size in inches » 2020-08-31 17:24:33

This returns size of first screen attached to current device in fact, as to get current screen you need to use combination of window_get_visible_rects + window_get_x/y to find on which screen game runs (except fullscreen - it's always on screen 1 from what I remember).

#17 Re: Script Submission » display_get_monitors_number » 2020-08-18 18:27:14

I just discovered this function 15 minutes before I made this post, when searching how to detect two monitors. And it was mentioned somewhere on YYG community between words by someone, but totally overlooked by others...

#18 Script Submission » display_get_monitors_number » 2020-08-14 17:38:54

gnysek
Replies: 2

pre-2.3

Expandreturn array_length_1d(window_get_visible_rects(0,0,1,1))/8;

2.3+

Expandreturn array_length(window_get_visible_rects(0,0,1,1))/8;

This returns the number of displays/monitors/screens on current PC.

#19 Re: Script Submission » Simple Debug Message Script » 2019-02-01 11:08:34

Expands+= (i > 0 ? ", " : "") + (is_real(argument[i]) ? string(argument[i]) : ("\"" + string(argument[i]) + "\""));

Then you can differ number from string, may be helpful in some debug cases.

#20 Re: Script Submission » Simple Debug Message Script » 2018-11-05 10:29:20

In gms2 you can do

Expands+= (i > 0 ", " : "") + string(argument[i]);

which make it even more beautiful smile

Board footer

Powered by FluxBB