-1
\$\begingroup\$

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
            Linked = true; //the gem's now linked

            var start_x = ds_stack_top(obj_Handle_Links.Link_Stack).x; //get the start point of the line
            var start_y = ds_stack_top(obj_Handle_Links.Link_Stack).y; //get the start point of the line
            show_message("did link");
            draw_line(start_x, start_y, x, y);

            ds_stack_push(obj_Handle_Links.Link_Stack, id) //adds the instance to the stack
\$\endgroup\$
  • \$\begingroup\$ 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)? \$\endgroup\$ – Ifn47 Jan 18 '18 at 4:08
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – SangoProductions Jan 18 '18 at 4:36
  • \$\begingroup\$ What event is this code in? \$\endgroup\$ – Miles Turin Jan 18 '18 at 4:37
  • \$\begingroup\$ Left Click event \$\endgroup\$ – SangoProductions Jan 18 '18 at 4:38
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Miles Turin Jan 18 '18 at 4:41
  • 1
    \$\begingroup\$ Simply put the same code in the draw event, except this time inside of this if statement: if(mouse_check_button_pressed(mb_left)) \$\endgroup\$ – Miles Turin Jan 18 '18 at 5:29

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.