Feedback inline scripts will they even be real? [SUGGESTION]

Discussion in 'GameMaker Studio 2 Community Tech Support' started by xDGameStudios, Mar 3, 2017.

  1. xDGameStudios

    xDGameStudios Member

    Joined:
    Sep 15, 2016
    Posts:
    579
    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!
     
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,404
    Technical term: closures.

    I kind of liked using "script tabs" in 1.x for this purpose.
     
    Kuro and csanyk like this.
  3. xDGameStudios

    xDGameStudios Member

    Joined:
    Sep 15, 2016
    Posts:
    579
    how would you go on using "script tabs" to help?!
    keep all conditions on a script on script tabs?! (like that?)
     
  4. csanyk

    csanyk Member

    Joined:
    Jun 20, 2016
    Posts:
    821
    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.
     
  5. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,404
    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.

    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.
     
  6. xDGameStudios

    xDGameStudios Member

    Joined:
    Sep 15, 2016
    Posts:
    579
    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
     
  7. babyjeans

    babyjeans Member

    Joined:
    Dec 3, 2016
    Posts:
    104
    I'm just curious as to the use case you mean there with rewriting files? It sounds interesting!
     
  8. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,404
    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.
     
    babyjeans likes this.
  9. Kuro

    Kuro Guest

    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: May 9, 2017
    Archer6621 likes this.
  10. TheMagician

    TheMagician Member

    Joined:
    Jun 20, 2016
    Posts:
    57
    The roadmap contains this item: GML: Inline functions - allow var a = function( a, b ) { ….. }
    Is that what you're looking for?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice