1
\$\begingroup\$

Situation: I started work on a pet project recently. It's a bit like Puzzlecraft, or Bejewled, but slightly different. You click one gem, as we'll call it, and if it's the first in the link, then it's added to the link.

That works well enough. However, the problem comes in that after that, in order to link, it must be adjacent to the last link... and somehow, something goes wonky. The first time you click something not adjacent, it doesn't get put on the link...or it at least doesn't highlight. It also doesn't run across any of my show_message popups - aside from "second else".

Yet, somehow, it seems to act as though that one you clicked on was the Last_Link, after that point...permanently...which shouldn't even be possible...

So, if you click adjacent to the one that got to "second else", it will still consider that "adjacent", even if it's across the entire board from the last one that actually highlighted.

And this permanent allocation of Last_Link can happen for every gem on the board. At the same time. (Note: It does deallocate once you restart the program.)

This DOESN'T make sense!

I have no step events (yet). This is also the only left click event in the game at the moment. Every other event is a create or game start event, mostly for initialization purposes. So I have no idea what is doing this. Can someone tell me?

Left Click Event for the Gems


if (obj_Handle_Links.Match_Length = 0) //if this would be the first in the link
{
    show_message("first to link");
    obj_Handle_Links.Match_Length +=1; //because we're increasing the length
    image_index = 1; //this should highlight
    //add to link, later
    show_message( Matrix_Location_y );
    obj_Handle_Links.Last_Link = id; //makes it so this is what's seen as last link
    show_message(obj_Handle_Links.Last_Link.Matrix_Location_y);
}
else
{   
    // show_message("first else");
    //check if the target is the same type as the last Link's type
    if(obj_Handle_Links.Last_Link.Type = Type &&
        //check if the last link in the chain is adjacent to the target link
        //includes diagonals
         (obj_Handle_Links.Last_Link.Matrix_Location_y = (Matrix_Location_y-1)
         || obj_Handle_Links.Last_Link.Matrix_Location_y = (Matrix_Location_y+1)
         || obj_Handle_Links.Last_Link.Matrix_Location_x = (Matrix_Location_x-1)
         || obj_Handle_Links.Last_Link.Matrix_Location_x = (Matrix_Location_x+1)) )
        {

            show_message( Matrix_Location_y );
            //show_message("third if");
            obj_Handle_Links.Match_Length +=1; //because we're increasing the length
            image_index = 1; //this should highlight
            //add to link, later
            obj_Handle_Links.Last_Link = id; //makes it so this is what's seen as last link      
           show_message(obj_Handle_Links.Last_Link.Matrix_Location_y);
         }
    else{

        show_message("second else");
        //play sound that link failed
    }
}
\$\endgroup\$
  • \$\begingroup\$ Can you make your title a little more relevant to the problem you're having? Titles like the one you currently have are very bad for people searching for similar problems in the future. And remember that tags go in the tags section, not the title. \$\endgroup\$ – MichaelHouse Jun 14 '16 at 15:39
  • \$\begingroup\$ OK. Will do. I'm bad with names. Doesn't help that I don't know what's going on myself. So, I just tried my best. Hope you like the new title. \$\endgroup\$ – SangoProductions Jun 14 '16 at 15:40
  • \$\begingroup\$ I strongly suggest you to put semicolons at the end of any command, as it is a good practice along with proper indentation to keep the code easily readable and understandable. \$\endgroup\$ – liggiorgio Jun 14 '16 at 21:38
  • \$\begingroup\$ right. I forgot to indent the show_message stuff because I intentionally put them out of indent for ease of finding them in the code later. Thanks. I have indented them for the question. \$\endgroup\$ – SangoProductions Jun 15 '16 at 2:27
0
\$\begingroup\$

I found the reason why it wasn't working as expected - it's because it's checking if it's within the entire row above and below, as well as the entire column to the left and right.

It was sheer coincidence (due to the small size of the map), that it seemed to be adjacent to a clicked object that was previously clicked on that wasn't assigned to a link.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.