1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

beginner question

Discussion in 'Programming' started by kaptenr, Feb 13, 2019 at 9:22 PM.

  1. kaptenr

    kaptenr Member

    Joined:
    Oct 25, 2018
    Posts:
    4
    Hi I am beginner in game maker, and I have a question, maybe someone know this?

    I have code that look like this in the step event.

    if (var_doNothing = true) {
    sprite_index = spr_default;
    }

    My question is, will this then happen every frame? Will it keep on putting the sprite_index each and every frame? will this take performance issues? If I get performance issues should I make like a variable so this only happens one time?

    Thanks :)
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    3,551
    If it's in the Step event, it happens every frame.
    This makes no sense. You're just setting a variable. If you have sprite_index set, the sprite would be drawn once per step (and per view if you have them on), just as if you left sprite_index alone.
    Not on its own. If you have thousands of instances of this object, then maybe. But the bottleneck there would likely be the excessive number of sprite draws and the huge lineup on the step cycle itself, not an itty bitty if statement.
    I want you to dump these kinds of baseless, anxiety-driven questions until you have formal computer science experience to discern what matters and what doesn't. The same goes to all the rookies around here asking all day about "the fastest and best" way to do things.

    First, as I have already mentioned, an if statement containing only a comparison and an assignment is a flyweight in the grand scheme of things.

    Second, updating continuously is NOT the same thing as updating on a one-off basis, and only one of these is right. You have to consider whether var_doNothing is continually updated. If it is, then it has to stay in the Step event to be correct. If isn't, then the correct sprite_index would be known at the point of the Create event, so just set it there. Doing the right thing should always come first. Doing wrong things fast only makes you look stupid faster.

    When rookies agonize over performance, their concerns are almost always in the wrong places. They end up putting "micro-optimizations" in places that don't matter in the big picture. Sometimes they get a tiny boost, but just as often they lose code maintainability, in other times they actually lose performance, and almost always they lose correctness.

    Don't start thinking about performance issues until you know you're doing the right thing. Don't start worrying about performance issues until the scale of the operation is in the thousands of something. Premature optimization is the root of all evil.
     
    Last edited: Feb 13, 2019 at 10:18 PM
    Binsk likes this.
  3. kaptenr

    kaptenr Member

    Joined:
    Oct 25, 2018
    Posts:
    4
    Okay I will keep the things you said in mind. Now it feels better, thanks so much for your answer! :D
     
  4. Toque

    Toque Member

    Joined:
    May 25, 2017
    Posts:
    671
    I think the cosmonaut space rocks tutorial covers a lot of your questions.

    It covers a lot and goes through quickly. But I’ve watched it three or more times and it’s helpful with the basics.

    Happy coding.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice