• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • 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.

Discussion [Suggestion] Lambda / Inline script support

babyjeans

Member
It'd be great if we were able to use lambdas while scripting... being able to set an array argument to script inline, or pass script as an argument to be executed by another script would be convenient.

I know that we can just make a bunch of actual script objects in the editor and call those - but to make it a little more manageable when its a one-off style thing you want to do, or call a script with varying arguments, lambdas could help.

Any thoughts?
 

babyjeans

Member
That's the exact thing I'd love to use it for! The little tweener system I wrote would love to inline its "onComplete" callback.
Sure it's workable without, but it'd be sooo nice.
 

ZeDuval

Member
I familiarized with this when I worked alot with Jquery. It would be awesome to be able to write something like this in GML:

Code:
myButton = ui_button_create(32,32,120,40,c_orange,c_white,"Shout!");

/// ui_button_on_click(button_handle,action)
with(argument0){
  if mouse_x > x && mouse_x < x+w && mouse_y > y && mouse_y < y+h{
    script_execute(argument1);
  }
}

// Step
ui_button_on_click(myButton,script(){
  show_message("I AM THE GOD OF HELLFIRE!");
});

// or some time in the future ;)
myButton.onClick(script(){
  show_message("I AM THE GOD OF HELLFIRE!..from the future!");
});
 
R

rui.rosario

Guest
We could also go either for Gosu-based lambdas
Code:
// One-liner
custom_executor(\ var1, var2 -> show_message(string(var1) + string(var2)));
Code:
// Several lines
show_debug_message(\ -> {
    var total = score - health;
    return string(total);
});
Or Java-based lambdas
Code:
// One-liner
custom_executor((var1, var2) -> show_message(string(var1) + string(var2)));
Code:
// Several lines
show_debug_message(() -> {
    var total = score - health;
    return string(total);
});
 
S

Schyler

Guest
You can do this with passing script identifiers, the only feature missing is "bind" or partial application.

I would vote against this as I don't feel this is a good use of resources and would make GameMaker more difficult for newcomers.

10 years ago, as a little kid, I had difficulty in finding how to access a "return" value as the manual didn't say explicitly. Can you imagine how difficult it must be to pickup GML now? Don't forget that as much as there have been good titles come out of GM:S, it's still an educational tool. If you're looking for rocket-powered functional programming goodness, go use Haskell instead.
 
Last edited by a moderator:

GMWolf

aka fel666
We could also go either for Gosu-based lambdas
Code:
// One-liner
custom_executor(\ var1, var2 -> show_message(string(var1) + string(var2)));
Code:
// Several lines
show_debug_message(\ -> {
    var total = score - health;
    return string(total);
});
Or Java-based lambdas
Code:
// One-liner
custom_executor((var1, var2) -> show_message(string(var1) + string(var2)));
Code:
// Several lines
show_debug_message(() -> {
    var total = score - health;
    return string(total);
});
I much prefer java lambdas...

But before we get lambdas, it would make a lot more sense to implement the obj.script() notation first
:)

You can do this with passing script identifiers, the only feature missing is "bind" or partial application.

I would vote against this as I don't feel this is a good use of resources and would make GameMaker more difficult for newcomers.

10 years ago, as a little kid, I had difficulty in finding how to access a "return" value as the manual didn't say explicitly. Can you imagine how difficult it must be to pickup GML now? Don't forget that as much as there have been good titles come out of GM:S, it's still a great educational tool. If you're looking for rocket-powered functional programming goodness, go use Haskell instead.
I dont think it would make it harder: Its a fully optional thing to use.
I my entire uni course covered java without once mentioning lambdas (using anonimous classes instead). In fact, many aspecs of java dont need to be understood to use java (think anotations, etc).

The same could be said with GML once it gets more features.
In fact, currently, I would say most people proficient with GML dont fully understand the behaviour of GML arrays (when it passed as a reference, and when it gets copied...). And yet, they can still make use of GML just fine :)
 

gnysek

Member
object which should execute binded script:
Code:
// create
binded_script = -1;

// step
if (binded_script > -1) {
    script_execute(binded_script);
}
then
Code:
with (instance_create_depth(some_object, 0, 0, 0)) {
   binded_script = some_script;
}
annonymous functions have no sense in GM:S, as there are even no normal "functions" you can define in code. I know that in some way we can call scripts a functions, but still, it's not same for me.
And above code can be extended using arrays, that several scripts can be binded and for more events, it just requires more code (and it can be a parent for others).
 

ZeDuval

Member
annonymous functions have no sense in GM:S, as there are even no normal "functions" you can define in code.
Whether a "normal function" gets defined in code
Code:
function functionName(params){functionBody}
or by creating a script resource with a scriptName and adding scriptBody with param/arg definition there, it's the same(taking about function declarations, not function expressions), isn't it? And how is the usefulness of anonymous functions bound to this anyway?

This whole thing is not about binding scripts/functions/code to objects. It's about being able to, for example, write general-functionality scripts like on_click, which code would be shared by all buttons and more gui elements(this is what scripts are for - "don't repeat yourself"), while coding the specific on_click_action inline because it might very well be different for every clickable gui element(This is where something else would be right, something more handy than the switch/case madness that occurs by utilizing the given tools...).

it just requires more code (and it can be a parent for others).
Now is the time to provide the motivated and very community-involved yoyo-team with ideas, suggestions and improvements for the new iteration of something we all love and will be using for years. At some point in the future, answers will be less like "We're discussing this right now internally, we'd also love it to be implemented" and more like "Yeah maybe in the next GM version WHICH WILL TOTALLY NOT BE NAMED GAMEMAKER 3!!", which is completlely understandable and normal, the later in the product lifecycle.
 

babyjeans

Member
You can do this with passing script identifiers, the only feature missing is "bind" or partial application.
annonymous functions have no sense in GM:S, as there are even no normal "functions" you can define in code. I know that in some way we can call scripts a functions, but still, it's not same for me.
And above code can be extended using arrays, that several scripts can be binded and for more events, it just requires more code (and it can be a parent for others).
Not looking to bind to objects, just looking to add short hand scripts to single functions, like @ZeDuval described:

This whole thing is not about binding scripts/functions/code to objects. It's about being able to, for example, write general-functionality scripts like on_click, which code would be shared by all buttons and more gui elements(this is what scripts are for - "don't repeat yourself"), while coding the specific on_click_action inline because it might very well be different for every clickable gui element(This is where something else would be right, something more handy than the switch/case madness that occurs by utilizing the given tools...).
And finally:

If you're looking for rocket-powered functional programming goodness, go use Haskell instead.
No thanks, this isn't about functional programming at all.
 

gnysek

Member
Yeah, this proposal makes things shorter, but it's possible to achieve with current code.

But this would require to make possible to make "variable_name()" works same as "script_execute(variable_name)" - which may lead to lot of issues I think, which cannot be found on compile time.
 

GMWolf

aka fel666
Yeah, this proposal makes things shorter, but it's possible to achieve with current code.

But this would require to make possible to make "variable_name()" works same as "script_execute(variable_name)" - which may lead to lot of issues I think, which cannot be found on compile time.
Yes, its possible without.
But guess what: its possible to make games without GM in C.
Its even possible to make games In an assembler language.

But this makes things easier. Making a new script for every small callback action is not always ideal.

A lot of modern languages have added lambdas because they are just soon convenient.
For instance, adding your own timeline code. You could see each event on the timeline in the sane code window.

Though, if this is added, it also makes a lot of sense to add the ability to define scripts in code.

I doubt this will get implemented. There are many things which should take precedence. like the dot notation for calling scripts, for instance.
 

babyjeans

Member
Realistically, it would make timelines about 1000x more useful too. And yes, I am aware you can do without them, my entire point was that to do things such as click handlers or callbacks that are 1-off things, you end up adding a billion 1-line GML script files.

I'm merely suggesting it'd be much easier to handle larger projects with features like these, and I've seen it mentioned that GMS2 is hoping to pull in more of the professional crowd. Right now, even small projects can be unwieldy when trying to write re-usable code for stuff like this.

EDIT: But thanks everyone, I think this topic has probably run its course. I see we're just repeating ourselves.
 
Top