Note: it's now possible to use a default for the first argument but still pass in for example, the second or a later argument by doing: ----my_func( , 1) In that example, it'll use the default for the first argument and "1" for the second. You can even do crazy stuff like: ----my_func( , , , 3, , 4) Don't know when they added it, but it's SO NICE. ❤
Hey I just wanted to say that you are one of my favorite channels on youtube for GameMaker content. Your videos are incredible and you're really great at explaining different concepts. Keep up the great work!
I like how you can pass functions in functions (just like you did with alarm_event), but does that only work when you know how many arguments that function will have? For example, if the user basically calls alarm_event(arg1,arg2,arg3..), will it throw an error because alarm_event is expected to run without any arguments?
I'm not entirely sure I understand the question, but in this particular example, the alarm_event shouldn't use any arguments because when it is called, no arguments are being passed in.
@@SamSpadeGameDev Thank you! Basically, my question was how to run a function inside a function if you dont know how many arguments the user can give but I think I found out a solution function func_runner(func) { func() } func_runner( function(arg1, arg2....etc) {... } ) This works! Though, the scope of the arguments is kinda weird
Previously I'd just been passing in whole numbers, checking if they aren't zero and then just having stuff run based on that. I had the one calling the function regulate whether the inputs where zero or not. It sounds great, but I hope I don't have to rebuild a whole project If I update.
I know there were some issues with the update for some people: forum.yoyogames.com/index.php?threads/2-3-3-stable-release-thread.87375/page-3#post-524002. I haven't experienced any, but I mostly have small projects. My guess is any serious ones will be fixed within the next week or so.
Not that I'm aware of. Arguments get assigned in the order they're passed in, so if you pass in one argument its value is always assigned to one in your example.
You can get the default value for any argument by passing it a value of undefined. In your example, you could call function(undefined, 42) and argument one would have a value of 0 and argument two would have a value of 42.
@@ultraken Thanks for rply. I am wanting to pass just what I want cuz I dont want to type everything that I want to be default. My example is very simple, but in my project, the arguments can be something like, 15,20 arguments, idk at now, but will be a huge number. I am looking to others way so solve it.
Do you mean that the value passed in is 15 or 20 or that the function has 15 to 20 arguments? If the latter, it might be worth asking on the GMC forum for suggestions on refactoring the function. It is very rare that a function needs more than 3 or 4 arguments and they almost never need more than 5 or 6.
I assumed 15 or 20 different arguments. One possible solution for that would be to pass a struct to the function instead of a whole bunch of separate arguments. (That's often done in programming languages like C/C++)
True. From what I understand, Playtech didn't really support YoYo, so, while there were improvements, anything that was nice, but not technically necessary, was but on the backburner. Since Opera took over though, YoYo has been putting out consistent updates, promoting GameMaker more, making official tutorials, and so on. Hopefully, this will work for them and they'll continue to do it since, as a long-time fan of GameMaker, it's been nice.
Note: it's now possible to use a default for the first argument but still pass in for example, the second or a later argument by doing:
----my_func( , 1)
In that example, it'll use the default for the first argument and "1" for the second.
You can even do crazy stuff like:
----my_func( , , , 3, , 4)
Don't know when they added it, but it's SO NICE. ❤
Hey I just wanted to say that you are one of my favorite channels on youtube for GameMaker content. Your videos are incredible and you're really great at explaining different concepts. Keep up the great work!
I think I didn't get anything but I like the delivery, thank you.
Thank you!😀
Thank you!
Please don't stop doing God's work. Thank you.
Not planning to :)
I like how you can pass functions in functions (just like you did with alarm_event), but does that only work when you know how many arguments that function will have? For example, if the user basically calls alarm_event(arg1,arg2,arg3..), will it throw an error because alarm_event is expected to run without any arguments?
I'm not entirely sure I understand the question, but in this particular example, the alarm_event shouldn't use any arguments because when it is called, no arguments are being passed in.
@@SamSpadeGameDev Thank you! Basically, my question was how to run a function inside a function if you dont know how many arguments the user can give but I think I found out a solution
function func_runner(func) {
func()
}
func_runner( function(arg1, arg2....etc) {... } )
This works! Though, the scope of the arguments is kinda weird
Previously I'd just been passing in whole numbers, checking if they aren't zero and then just having stuff run based on that. I had the one calling the function regulate whether the inputs where zero or not. It sounds great, but I hope I don't have to rebuild a whole project If I update.
I know there were some issues with the update for some people: forum.yoyogames.com/index.php?threads/2-3-3-stable-release-thread.87375/page-3#post-524002. I haven't experienced any, but I mostly have small projects. My guess is any serious ones will be fixed within the next week or so.
have any to pass just one argument that I want?
for example:
function(one=0, two=0)
I want to pass just the argument two, have any way?
Not that I'm aware of. Arguments get assigned in the order they're passed in, so if you pass in one argument its value is always assigned to one in your example.
You can get the default value for any argument by passing it a value of undefined.
In your example, you could call function(undefined, 42) and argument one would have a value of 0 and argument two would have a value of 42.
@@ultraken Thanks for rply. I am wanting to pass just what I want cuz I dont want to type everything that I want to be default. My example is very simple, but in my project, the arguments can be something like, 15,20 arguments, idk at now, but will be a huge number. I am looking to others way so solve it.
Do you mean that the value passed in is 15 or 20 or that the function has 15 to 20 arguments? If the latter, it might be worth asking on the GMC forum for suggestions on refactoring the function. It is very rare that a function needs more than 3 or 4 arguments and they almost never need more than 5 or 6.
I assumed 15 or 20 different arguments. One possible solution for that would be to pass a struct to the function instead of a whole bunch of separate arguments. (That's often done in programming languages like C/C++)
This took only like 3 years to be added ... wow
True. From what I understand, Playtech didn't really support YoYo, so, while there were improvements, anything that was nice, but not technically necessary, was but on the backburner. Since Opera took over though, YoYo has been putting out consistent updates, promoting GameMaker more, making official tutorials, and so on. Hopefully, this will work for them and they'll continue to do it since, as a long-time fan of GameMaker, it's been nice.