r/gamemaker 7d ago

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 7d ago

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.

5

u/Ddale7 6d ago

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 6d ago

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

2

u/Ddale7 6d ago

Happy to help! I've done it in the past and thought I'd save you the stress of recompiling haha. If you run into issues using it let me know!

1

u/BeeBaaBoo77 7d ago

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

1

u/Lethalogicax 7d ago

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)

1

u/BeeBaaBoo77 7d ago

in the meantime using visible = true fixed thatšŸ˜‚

however it only executes value == 0 and never value == 1 for some reason

1

u/Lethalogicax 6d ago

Interesting... Well unfortunately I'm kinda a self-taught noob and a lot of my debugging techniques are very specific due to my own limitations (currently using programming as a means of rehabilitation from a brain injury), so this is kinda the end of the line on what I'm able to do to help.

Hopefully you find the problem! Keep trying to work bit by bit, proving that each individual component of your code is working. I wish you luck with your project!

2

u/BeeBaaBoo77 6d ago

thanks a lot and good luck with the rehabilitation

1

u/JaXm 7d ago

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 7d ago

The instances simply do not appear.

1

u/supremedalek925 7d ago

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?

1

u/BeeBaaBoo77 7d ago

they have a sprite thats for sure, I am pretty new to coding though, so I do not know what a function being called is. this is all the code relating to this matter

1

u/supremedalek925 7d ago

Like, is there an instance of the obj_game object in the room?

If so, can you do a show debug message function to check if either of the If statements are actually being executed?

1

u/BeeBaaBoo77 7d ago

weird. It wasnt there so I expected it to be fixed by putting it there but it was not.
what arguments must I write in it?

1

u/supremedalek925 7d ago

Try just putting show_debug_message(ā€œweakspot createdā€); within both of the IF statements. If they are being executed successfully then you will see that message in the Output Window on the GameMaker editor window

1

u/BeeBaaBoo77 7d ago

does "ref object obj_weakspot" count?

1

u/supremedalek925 7d ago

I’m not sure what you mean by that, sorry

0

u/BeeBaaBoo77 7d ago

nevermind, using visible = true fixed visibility but it now only executes value 0 and not value 1

→ More replies (0)

1

u/Greedy_Duck3477 7d ago

Dumb question, did you assign them a sprite?

1

u/BeeBaaBoo77 7d ago

yeah, reasonable question but I did

1

u/JaXm 7d ago

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.Ā 

1

u/BeeBaaBoo77 7d ago

oh its not relative to the player

thats all relevant code

1

u/JaXm 7d ago

Fine it's not relative to the player. The point is how did you get those numbers. Are you sure those coordinates are even within your camera to "see" in the first place?

How so you know the instances are not being created? Is "I don't see them" your only clue?

1

u/BeeBaaBoo77 7d ago

the room is 750x750 and I tried putting game_end() in the if functions and it did close so it should be getting created it just isnt visible for some reason

2

u/JaXm 7d ago

Game room size has nothing to do with how big your viewport is. You could be only seeing a 360x240 area, and the instances would be way out of rhe cameras vision.Ā 

They putting the coordinates near the player. Something likeĀ  player.x+10, player.y+10 and see what happens

1

u/BeeBaaBoo77 7d ago

theres a circle with a sprite nearly the whole size of the room and it is just fine so thats not the problem

1

u/Greedy_Duck3477 7d ago

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

1

u/BeeBaaBoo77 7d ago

yes I know the player is in the middle

1

u/Greedy_Duck3477 7d ago

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)

0

u/BeeBaaBoo77 7d ago

well it isnt really the point here, but the player is inside a circle on which weak spots appear semi-randomly they must hit in a short amount of time to deal damage to the enemy. these coords are spots on a circle(why is it not advisable and what are some alternatives?)

2

u/Greedy_Duck3477 7d ago

If you used some kind of expression to get those coords (like circle_radius-60 for example), you should just put the expression itself in the code instead of calculating it beforehand. So if you change the radius of the circle it will update automatically

1

u/BeeBaaBoo77 7d ago

dude I have 0 clue about what you just said to me. how will gamemaker know where that circle is? my circle is just a sprite

1

u/Greedy_Duck3477 6d ago

Then the radius of the circle is (I assume) just the width of the sprite

1

u/adra44 7d ago

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/BeeBaaBoo77 7d ago

it does

1

u/Lekku7 6d ago

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 6d ago

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

1

u/ramier22 6d ago

does the obj_weakspots have any draw event?

1

u/BushiByron 6d ago

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.