With Statement [GameMaker Studio 2]

Поділитися
Вставка
  • Опубліковано 10 лют 2025

КОМЕНТАРІ • 13

  • @Fearnbus25
    @Fearnbus25 4 роки тому +14

    Sadly this did not help me with my problem, but there is no denying that this is an extremely well made and informative tutorial. I hope you continue making such great videos in the future. 10/10

  • @leko_top4z600
    @leko_top4z600 10 місяців тому

    Couldn't find a better tutorial on this topic. Clear points, easy to follow, and with helpful examples. Thank you for this.

  • @Sly14000
    @Sly14000 5 років тому +8

    These are very high quality. Subscribed.

  • @naturallynemo
    @naturallynemo 3 роки тому +4

    Great Video

  • @etclee6630
    @etclee6630 3 роки тому +4

    really helpful! thank you!

  • @jasongieske817
    @jasongieske817 6 місяців тому

    Worth noting that local variables declared prior to the with statement will still be in scope inside the with statement.

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

    what if i make an object and i wanna add a variable to it

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

    what about with (other)?

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

      Yep, perfectly valid.
      obj_player's Collision Event with obj_bullet:
      hp -= 5; // player instance's hp
      with (other) { // other now changes the scope to the colliding bullet instance
      instance_destroy(); // the bullet instance gets destroyed
      }

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

      Also, going with his obj_with_statement example:
      with (my_inst) { // scope is changed to the obj_white_dot instance
      show_debug_message(object_get_name(object_index)); // from the my_inst scope, this will output "obj_white_dot"
      show_debug_message(object_get_name(other.object_index)); // from the my_inst scope, other refers back to obj_with_statement and will output that
      with (other) { // scope is changed further to other ... i.e., scope is changed to obj_with_statement
      show_debug_message(object_get_name(object_index)); // from the obj_with_statement scope, this will output "obj_with_statement"
      show_debug_message(object_get_name(other.object_index)); // from the obj_with_statement scope, other refers back to obj_white_dot and will output that
      }
      }

  • @marcuskane3187
    @marcuskane3187 4 роки тому +2

    I just want to say that this function can be very dangerous... It can cause performance issues really fast , also there are better workarounds for this function, I suggest only to use it when its impossible not to. Simply because it is also very hard to debug if you have lot of objects or running it all the time.

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

      Are you referring to the with statement? The with statement is in general the fastest way to check multiple instance of an object, and in some cases even the fastest way to deal with referencing a single instance of an object (some people who have tested it have reported it as being faster for them even than the dot accessor with an instance id).

    • @SamSpadeGameDev
      @SamSpadeGameDev  4 роки тому +5

      It might depend as well on which platform your using, but on PC using the VM with outperforms the . accessor by a fair bit while in the yyc build the . accessor is faster for a single variable and the with statement is faster for multiple using the code here: forum.yoyogames.com/index.php?threads/about-with-statement-performance.48829/