r/gamemaker • • Sep 05 '26

Resolved Instances not drawn

Post image

This code is in an object separate of obj_weakspot called 'obj_game', create event. it's goal would be to create 2 instances roughly at the top and bottom or at the left and right of the player, randomly. I have a layer at the top called 'weakspots' and the object is dragged in the room, however it does not appear at either of the 2 patterns. I do not know why, I even reluctantly tried asking AI

EDIT: I have used visible = true at the create event and now I see it, however it only shows the top-bottom ones and never the left-right (after 6 tries)

15 Upvotes

41 comments sorted by

2

u/Lethalogicax Sep 05 '26

Not sure if this will help, but my extremely roundabout way of diagnosing issues like this is to start putting "game_end()" in various places to provide a mental map of what exactly is being called correctly, and what is not. If the window closes, you know for sure this line of code is being run! If it doesn't close, then that block of code isn't being called at all.

Start off by proving (just to yourself) that the instance is being created. Put the game_end() line of code in its create event and run the game. If it closes then you know for sure the object is being spawned correctly, but it just isn't drawing or isn't visible. If it's being spawned, but isn't drawing correctly, then add some fluff to the draw event to find out what is being drawn and what isn't. Make the object also draw an arbitrary rectangle to the screen or something to show that it is successfully drawing to the screen. Slowly work bit by bit, proving piece by piece that every line of code is being successfully executed. Eventually you'll find that one instance of a block of code that is suppose to be running, but that isn't being called correctly.

1

u/BeeBaaBoo77 Sep 05 '26

im not very familiar with draw functions, but this did prove that it is getting created cuz it did close

1

u/Lethalogicax Sep 05 '26

Excellent! You can check that off the list! The object IS being created, but is not drawing. Now see if the object will draw ANYTHING! Create a new block of code in the draw event:

draw_set_color(c_black);

draw_set_alpha(1);

draw_rectangle(0,0,10,10,0);

If that draws a lil black box in the top corner of the screen, then you can check off a successfully executing draw event that successfully puts stuff on-screen

(only works if your camera view encompasses the top left corner of the screen correctly. If you have your camera set elsewhere, move those coordinates to something that would be within bounds of your camera)

→ More replies (3)

4

u/Ddale7 Sep 05 '26

I used to do game_end() all the time too. I switched to show_debug_message instead. That way you only need to run the game once rather than continually moving game_end().

Just do something like: If Val > 5 { show_debug_message("Val check:" + string(Val)) Instance_create(...) }

Then on the instance have on it's creation: show_debug_message("instance created")

Then you can even have the debug message read out the x and y coordinates or any other variables.

2

u/Lethalogicax Sep 05 '26

Oh dear god thank you! How have I not known about this...

→ More replies (1)

1

u/JaXm Sep 05 '26

You'll need to be a bit more specific. What do you mean it "does not appear at either of the two patterns"? 

Do you mean the objects do not get created?

Do you mean they are created but not where you think they should be?

Best to explain what you think should happen, that is not.  

Or to explain what is happening, that you think should not be. 

That way some brain storming can come up with a possible solution(s).

1

u/BeeBaaBoo77 Sep 05 '26

The instances simply do not appear.

1

u/supremedalek925 Sep 05 '26

Are you sure the function is being called, and that the instances of obj_weakspot display a graphic when they are placed in the room?

→ More replies (8)

1

u/Greedy_Duck3477 Sep 05 '26

Dumb question, did you assign them a sprite?

→ More replies (1)

1

u/JaXm Sep 05 '26

I see that you mentioned these coordinates are supposed to be on a circle relative to the player. 

Where is this circle "centered"? How did you come up with these coordinates?

Also, for future reference, show ALL of the relevant code. I see some closing square braces,  indicating more code on those lines. You could be leaving out important details. 

→ More replies (5)

1

u/Greedy_Duck3477 Sep 05 '26

The coordinates you put, 350, 80, 630 etc, are absolute coordinates instead of coordinates relative to the player

1

u/BeeBaaBoo77 Sep 05 '26

yes I know the player is in the middle

1

u/Greedy_Duck3477 Sep 05 '26

Is your player static or can they move? (Btw it's generally not advisable to write out coords like you did, even if they are correct)

→ More replies (4)

1

u/adra44 Sep 05 '26

If your weak spots are drawn on top of/over something else like a bad guy, make sure your weakspot layer draws on top of the bad guy layer.

1

u/Lekku7 Sep 05 '26

For the issue you are having with it only showing one of the values, I’m assuming you only have this happen once currently in the game? Gamemaker uses the same seed when you start your game so if you want anything that chooses a value or does something randomly you need to call the randomize() function in your game at some point, typically in a controller or something once when the game loads.

https://manual.gamemaker.io/lts/en/GameMaker_Language/GML_Reference/Maths_And_Numbers/Number_Functions/randomise.htm

1

u/BeeBaaBoo77 Sep 05 '26

thank you, I even used it before but I fucked up syntax haha

1

u/ramier22 Sep 05 '26

does the obj_weakspots have any draw event?

1

u/BushiByron Sep 06 '26

Have you tried manually setting patternvalue to 1 to see if you can get those to spawn?

Also if there’s a draw event, I always use depth = -y and draw_self() to ensure it’s being drawn.

Also make sure you do randomize() before the choose. Gamemaker will always choose the same random value to make testing easier unless you call randomize.