1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

what is wrong with this code?

Discussion in 'Programming' started by lamatoast, Jan 16, 2018.

  1. lamatoast

    lamatoast Member

    Joined:
    Aug 12, 2017
    Posts:
    42
    if !place_meeting(x-40,y,obj_grass) and !place_meeting(x+40,y,obj_grass)
    {
    with(other)
    {
    instance_destroy()
    }
    }
     
  2. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    Possibly 'other' is not being recognized because there is no meeting occuring between the calling instance and obj_grass, which may result in some object besides obj_grass being destroyed or nothing happening at all.
     
  3. JFitch

    JFitch Member

    Joined:
    Sep 28, 2016
    Posts:
    428
    Is it in a collision event?
     
  4. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,684
    other is out-of-context in all situations except for the following two:
    • Inside an actual collision event (i.e. the kind from the event selector, NOT an if block in a Step event)
    • Inside a with block (the selecting expression does not count unless it is in an actual collision event or nested inside another with block)
    You need to look at where your piece of code comes from and carefully consider whether other makes sense in that context, and if so what it refers to.
     
    Blackened likes this.
  5. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    827
    I'm confused, you're checking if there isn't an instance of grass to the left or right and then trying to destroy something. What are you trying to destroy?
     

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