You are not logged in.
For sure it doesn't as draw_rectangle doesn't draws rotated rectangles.
For linux version, for sure this works:
function 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;
}
Shouldn't it also take "sprite_get_speed_type" into account?
I believe that script style guide could be updated
/// @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);
}));
}
/// @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:
array_test = [10, 20, 70];
show_debug_message(array_sum(array_test));
// returns 10+20+70 = 100
/// @param {array} a
/// @returns {undefined}
function array_shuffle(a) {
/// @returns {real}
static _shuffle = function() {return choose(1, -1);}
array_sort(a, _shuffle);
}
usage:
var a = [1, 2, 3, 4, 5, 6];
array_shuffle(a);
show_debug_message(a); // for example: [ 5,2,1,4,3,6 ]
So, for 2022, most up-to-date version (including <= fix) will be:
/// @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;
}
??
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).
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.
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.
Edit: updated with faster version by @maras:
function is_int(number) {
return floor(number) == number;
}
Old, less efficient version:
function is_int(number) {
return sign(frac(number)) == 0;
}
Results for both:
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(-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
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.
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 ?).
Of course not. I was rather thinking about covering all possibilities, but then script will be much bigger.
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).
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...
pre-2.3
return array_length_1d(window_get_visible_rects(0,0,1,1))/8;
2.3+
return array_length(window_get_visible_rects(0,0,1,1))/8;
This returns the number of displays/monitors/screens on current PC.
s+= (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.
In gms2 you can do
s+= (i > 0 ", " : "") + string(argument[i]);
which make it even more beautiful