This line runs twice [SOLVED]

Discussion in 'Programming' started by Bentley, Jun 12, 2019.

  1. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    I'm curious why the line in the draw event runs twice.

    global mouse left pressed event
    Code:
    line_to_check = [point, prev_point]; 
    draw event
    Code:
    if (is_array(line_to_check)) // "if line_to_check != 0" will work but I want to know what I'm misunderstanding
    {
        // Delete array
        line_to_check = 0;
     
        show_debug_message("this line ran");
    }
    The debug message, "this line ran", shows up twice. I thought that setting an array to 0 deletes it and therefore the next frame would not run what's the code inside the is_array condition

    Maybe, b/c line_to_check equals 0, that is_array(0) is true b/c there is another array with that index? But there's only one array in the entire project.

    Thanks for reading.
     
    Last edited: Jun 12, 2019
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,965
    I'd check to see if you have more than one instance of an object. It might be worth putting a few of the following utility scripts into your project and using them instead so you can find out which object is calling that and on which frame, etc. :Using show_debug_message.

    You could also try line_to_check = -1 to test your theory since as far as I know no resource ever has a negative id number.
     
  3. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    @samspade Yeah, all those things came to mind as well. I'm just going to mark it solved. It's not a big deal anyway, I was just wondering why. It's as if it takes 2 frames to for the array to be recognized as deleted.
     

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