Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

j777ferrol-debug

2
Posts
1
Topics
A member registered 12 days ago

Recent community posts

(1 edit)

true true. I managed to make a better version. The huge block of code at the end of the for still annoys me tho.

#mfunc foreach(element, list) as "keyword" \
var list##_len = array_length(list); \ 
if (list##_len <= 0) {} \ 
else for (var element##_i = 0, element = list[0]; element##_i < list##_len; { element##_i++; if (element##_i < list##_len) element = list[element##_i] })

the built-in array_foreach function is really good but it has a few drawbacks like changing the context so i cant use local variables, making it really bothersome to use inside a method where i need the parameters.

This is what i came up with to try and replicate it:

#mfunc foreach(element, list) as "keyword" for (var _i = 0, _n = array_length(list), element = list[_i]; _i < _n; { _i++; if (_i < _n) element = list[_i] })
// which would look like this when used:
var list = [1, 2, 3, 4, 5];
foreach (num, list) {
    show_debug_message(num);
}
It works but i still have a few problems with it: you cannot nest these one inside the other because the variables used to traverse the array would end up with the same name (_i and _n), and the if-block at the end (required so it doesnt try accesing beyond the bounds of the array after the last iteration) is a bit ugly and cumbersome.