• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 inline scripts will they even be real? [SUGGESTION]

xDGameStudios

GameMaker Staff
GameMaker Dev.
I'm here to suggest something I think would be very useful!

What about a function like:

Code:
script_create({
     var a = argument[0];
     var b = argument[1];
     return a+b;
});
or pragma("script", { ... });

...that would let create a script inline without the need of making a script in the resource tree.. sometimes creating this scripts make the resource tree very overcrowded and sometimes you just need the script in a particular case just to be passed as an argument to another function (for example).

select_squares(grid, condition);

"condition" here is a function..

Code:
#select_squares

var grid = argument0;
var condition = argument1;
var out = ds_list_create();

for( i ...) {
   for( j...) {
      value = grid[# i, j]
      if (script_execute(condition, value)) {
         ds_list_add(out, value);
      }
   }
}

return out;


#condition

var value = argument0;
return value > 5;
here I have to create a function for just one simple thing.. it's not very practical.
what if I want to change the "5"... what if I want another logical operation "<" or ">="?

okay... I know condition could be:

Code:
#condition

var value = argument0;
var test = argument1;
var valid = argument2;

switch (test) {
     case TEST.EQUAL:
         return value == valid;
         break;
     case TEST.NOTEQUAL:
         return value != valid;
         break;
     case TEST.GREATER:
         return value > valid;
         break;
     default:
         return false;
}
but this would be a nightmare to maintain..
the script could even be dynamic, meaning you could use script_free(script) to release it!
 

csanyk

Member
Hmm, well compared to other languages, where you can have a .class file that has many methods defined in it, GML script resources do look cluttered.

I haven't found this to be a significant problem, but I also tend to work on smaller projects. I do see how it could be an issue with larger projects.

I don't know offhand whether GMS2 does it or not, but in GMS1 you could arrange related scripts in to tabs in the same resource, which maybe would help with the resource tree being cluttered.

In GMS2, you can also set up views of the resource tree so you can see what you want, as a way to manage clutter.

It wouldn't be bad if you could define multiple functions in a single file, too.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
how would you go on using "script tabs" to help?!
keep all conditions on a script on script tabs?! (like that?)
Yes - say, if you have a script "select_squares", a condition-helper sub-script would be named "__select_squares_cond" (to avoid it popping up in regular auto-completion). This way you never see it unless you are editing select_squares, and in that case it is conveniently available.

It wouldn't be bad if you could define multiple functions in a single file, too.
This is still supported for extensions (via "#define name" separators), and is an invaluable tool for anything automatically generated/assembled - rewriting a single file is always much faster than rewriting 300 tiny files.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
This is still supported for extensions (via "#define name" separators), and is an invaluable tool for anything automatically generated/assembled - rewriting a single file is always much faster than rewriting 300 tiny files.
Can this be used from within the IDE?! for example:

Script: VECTOR2D
Code:
#define vector_create

{..code..}

#define vector_add

{..code..}

#define vector_dot

{..code..}
EDIT: no it can't! :/ just tested... damn I was getting excited already
 

babyjeans

Member
This is still supported for extensions (via "#define name" separators), and is an invaluable tool for anything automatically generated/assembled - rewriting a single file is always much faster than rewriting 300 tiny files.
I'm just curious as to the use case you mean there with rewriting files? It sounds interesting!
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I'm just curious as to the use case you mean there with rewriting files? It sounds interesting!
Such as per-variable-name helper scripts shown here - if one had to make a separate 2-line script for each of auto-generated script, that take quite a while.

I also experiment with tweaking Haxe's JavaScript compiler to produce code that happens to be valid GML (since syntax is close enough), but that one is far off any sort of public release.
 
K

Kuro

Guest
Technical term: closures.

I kind of liked using "script tabs" in 1.x for this purpose.
Oh nice. Next time I'm using 1.x I'm going to milk the script tabs feature for all its worth. :D

As an aside I was browsing one of the other forum categories and discovered a thread about Gamemaker Jokes. It only took four jokes before one popped up about methods. lol
 
Last edited by a moderator:
Top