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

Optimization Help

Discussion in 'Programming' started by Marius Jmecherul, Jun 15, 2019.

  1. Marius Jmecherul

    Marius Jmecherul Member

    Joined:
    Jun 15, 2019
    Posts:
    1
    Hello,

    So I'm trying to make game, and while making it I'm trying to make it as optimized as possible. I'm using Game Maker 8.0 Pro.

    Which would be more optimized and less stressful for a computer to compute:

    OPTION A:------------------------------------
    if(invisible=1)
    {
    i=0;
    r=id;
    with(detector)
    {
    if(point_distance(x,y,r.x,r.y)<100)
    {
    i=1;
    break;
    }
    }
    }
    if(i=1)
    {
    //TARGET IS VISIBLE
    }
    else
    {
    //TARGET IS NOT VISIBLE
    }
    ---------------------------------------------------
    OPTION B:------------------------------------
    if(invisible=1)
    {
    i=0;
    if(instance_exists(detector))
    {
    r=instance_nearest(x,y,detector);
    if(point_distance(x,y,r.x,r.y)<100)
    {
    i=1;
    }
    }
    }
    if(i=1)
    {
    //TARGET IS VISIBLE
    }
    else
    {
    //TARGET IS NOT VISIBLE
    }
    ---------------------------------------------------

    The code is written inside an object that could go invisible but can be detected by a certain other object.
    Thanks.
     
  2. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,460
    I'd say B will be faster most of the time, since you use a compiled built-in function to loop through all the objects. On currently supported versions of GM, A should be faster most of the time (unless none of the objects can see you) since it doesn't need to loop over EVERY object if one of the first ones can see you.
     

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