Default Values for Optional Arguments Update [GameMaker Studio 2.3]

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 21

  • @meganinja456
    @meganinja456 Рік тому +1

    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. ❤

  • @sudobeats6978
    @sudobeats6978 3 роки тому +5

    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!

  • @Ruth-cz6lc
    @Ruth-cz6lc 3 роки тому +3

    I think I didn't get anything but I like the delivery, thank you.

  • @headspin4120
    @headspin4120 3 роки тому +2

    Thank you!😀

  • @FoxyOfJungle
    @FoxyOfJungle 3 роки тому +2

    Thank you!

  • @Ailwuful
    @Ailwuful 3 роки тому +3

    Please don't stop doing God's work. Thank you.

  • @Ldinos
    @Ldinos 2 роки тому +1

    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?

    • @SamSpadeGameDev
      @SamSpadeGameDev  2 роки тому +1

      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.

    • @Ldinos
      @Ldinos 2 роки тому +1

      ​@@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

  • @derpmorederp1417
    @derpmorederp1417 3 роки тому +2

    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.

    • @SamSpadeGameDev
      @SamSpadeGameDev  3 роки тому

      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.

  • @kyoto4167
    @kyoto4167 3 роки тому +1

    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?

    • @SamSpadeGameDev
      @SamSpadeGameDev  3 роки тому +1

      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.

    • @ultraken
      @ultraken 3 роки тому +1

      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.

    • @kyoto4167
      @kyoto4167 3 роки тому

      @@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.

    • @SamSpadeGameDev
      @SamSpadeGameDev  3 роки тому

      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.

    • @ultraken
      @ultraken 3 роки тому +1

      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++)

  • @yokmp1
    @yokmp1 3 роки тому +1

    This took only like 3 years to be added ... wow

    • @SamSpadeGameDev
      @SamSpadeGameDev  3 роки тому +3

      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.