variables holding programs



Hello, is it possible for variables to hold programs? I'm trying to use the choose function like this:

choose( control1, control2, control3)

in the create event I set up the variables:

control1 = { if keyboard_check(vk_up){ y -= 3}

(rest of keyboard inputs)


control2 =

It's not working, so I believe I'm using variables wrong or missing something.

I'm racking my brain trying to find a solution, I want the players controls to be switched if they have a collision with an object.
Last edited:


You cannot create lambda functions in GameMaker *yet*.

You should place the code you want into a script instead of setting it directly into the variable. Then you can set the variable to the script name instead. When you want to execute the code then you would do something like:


This should give you the result you are going for. Or, instead of storing the script names in variables, just put the names directly into the choose function.


Didn't even know what a lambda function was, I guess you learn something everyday. That solution worked along with some alarms, I used instance_create with the choose function to change my object.

Thanks :)