Why is the line not being drawn?

I'm trying to add a few polishing touches to my puzzle game (made in Game Maker) in the vein of Ironclad. The following code is for adding a gem object to a stack that already has at least one other object.

Everything works except the draw_line, for some reason. At first, I thought it was because ds_stack_top().x didn't actually return the x value of the object on top of the stack. So, I replaced the points with random values, and those didn't work. It clearly runs past the code, since "did link" prints out.

I'm not sure what I'm doing wrong.

            obj_Handle_Links.Match_Length +=1; //because we're increasing the length
image_index = 1; //this should highlight

draw_line(start_x, start_y, x, y);


• In game maker draw functions have to be in a draw event in order to run. Is your code on a draw event? Or maybe you need to set the draw color first, something like draw_set_colour(c_lime)? – Ifn47 Jan 18 '18 at 4:08

You want to draw the line from (0,0) to the point popped off of the stack, right? If so, then

draw_line(0, 0, x, y);

should be

draw_line(0, 0, start_x, start_y);

Also make sure the object drawing the lines is set to visible, otherwise it's draw events are skipped.

• My bad. No. That was one of my random points I had in debugging. I've edited it properly. It was supposed to be drawn from the stack's top object to the current object.The object where this code is done is visible. – SangoProductions Jan 18 '18 at 4:36
• What event is this code in? – Miles Turin Jan 18 '18 at 4:37
• Left Click event – SangoProductions Jan 18 '18 at 4:38
• Ah, there's your problem. In GameMaker, things will only be drawn if they are in a draw event. An easy way to fix this would be to move this code over into an if statement in the draw event that checks for left mouse button presses. – Miles Turin Jan 18 '18 at 4:41
• Simply put the same code in the draw event, except this time inside of this if statement: if(mouse_check_button_pressed(mb_left)) – Miles Turin Jan 18 '18 at 5:29