For Loops Basics [GameMaker Studio 2]

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

КОМЕНТАРІ • 13

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

    this tutorial is made in 2020 but my gamemaker tells me array_length_1d is absolete, why doesnt it say that in the tutorial?

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

      Good catch. This tutorial was made prior to the updates in 2.3 which made those functions obsolete. I do mention it in this tutorial though: ua-cam.com/video/K4-wc-1kc1k/v-deo.html.

  • @tutata
    @tutata 4 роки тому +6

    Thanks for covering this topic

  • @tomcrazyOMG5
    @tomcrazyOMG5 10 місяців тому +1

    Just want to say I've been crash-coursing GameMaker for the last 3 weeks, and your channel is by far the best video tutorial resource. Keep up the great work.

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

    thank you so much, this is so helpful

  • @joLicata91
    @joLicata91 Рік тому

    Hi Sam! Thank you for the tutorial!I have a question (about for loop) How can I play a sound everytime the variable ( i ) increment by 1?

  • @inceptional
    @inceptional 2 роки тому +2

    If I was trying to use a For loop to do this:
    instance_create(275, 90, ShipFlyby);
    instance_create(356, 105, ShipFlyby);
    instance_create(400, 121, ShipFlyby);
    How would I write it?
    I mean, I want to create 3 of the same ships (or more) but with each of them at different positions on the screen. And, because I tend to change things a lot (like exactly where I'd like each ship to be created so it looks good), I'd also like to be able to change each of those positions as and when too, so ideally those would also be written in a way that's easy to find, read and change them if necessary (particularly if there's a lot of ships being created).
    Also, would it make more sense to use a For loop or a Repeat loop for this, and what's actually the difference between those?
    Any help would be much appreciated.

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

      A repeat loop repeats however many times you specify and doesn't (by default) have an iterator variable. Your example is a little tough to convert to a for loop because I don't know how you're coming up with the x and y. But here's one example (not tested):
      ship_position_array = [[275, 90], [356, 105], [400, 121]];
      for (var i = 0; i < array_length(ship_position_array); i += 1) {
      instance_create(ship_position_array[i][0], ship_position_array[i][1], ShipFlyby);
      }
      This uses GameMaker Studio 2.3 syntax though which you might not be using since you've used instance_create. And, as you can see, it's actually more complicated (though more flexible) than the code you wrote.
      If you're never going to have more than three ships, and you want to set their positions manually, your code works well. But if you were going to have dozens of ships, or set their positions programmatically, then something like the above would be better.

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

      @@inceptional I've never used 8.1 so I don't know what's allowed. I know you can't chain accessors like that. I'm not sure if you can declare arrays that way. You'll probably have to ask on the GMC forums where some people still know what worked and what didn't back then.

    • @inceptional
      @inceptional 2 роки тому +2

      @@SamSpadeGameDev Cool, no probs. Thanks for the feedback. :)

  • @fierorecensione5828
    @fierorecensione5828 Рік тому

    Hello, is it possible that something like this is working?
    // add that item
    for(var i = 0; i < array_length(_itemToAdd); i++) {
    _gridToaddItem[# _newWidth - 1, i] = _itemToAdd[i];

    }

    // set amount of new item
    _gridToaddItem[# _newWidth - 1, i] = 1;

  • @jargontrueseer
    @jargontrueseer 2 місяці тому

    8:32 "At the end if this event, i will be destroyed."

  • @Far.aep_
    @Far.aep_ Місяць тому

    Me after seeing the exam 8:34