Trying to draw a non-existant sprite

JacktheLR

Member
I'm trying to draw a target to signify that my character is locked onto an enemy, but I get an error that says.

Trying to draw non-existing sprite.
at gml_Object_objhominglock_Draw_73 (line 4) - draw_self()
The code for drawing the event has a create event that has this code,:
draw = false;
radius = 75;
image_speed = 0.35;


A step event that has this,:
if radius > 15
radius -= 6
else
draw = true

if Sonic.action == -5
instance_destroy()

x = instance_nearest(x,y,objhomingtarget).x
y = instance_nearest(x,y,objhomingtarget).y


And a draw end event that has:

if draw
draw_self()
else
{
draw_set_circle_precision(32)
draw_set_colour(c_lime)
for(i = 0; i < 2; i+=0.1)
draw_circle(x,y,radius-i,true)
}


Apparently the error comes in at draw_self(). Why is this and what can I do to fix it?
 
Add the following line just before your draw_self() command:
show_debug_message("SPRITE: "+sprite_get_name(sprite_index));
Then check the output console to see what sprite it has assigned.
 

TheouAegis

Member
Keep in mind that by default be draw a event will not draw anything if there is no Sprite assigned. However, you are not using the drop event by default, you are putting coating it and calling draw_self(), so it now requires a sprite. You could arguably file a bug report and ask YYG to make draw_self() in future versions exit prematurely if no Sprite is assigned.
 

Slyddar

Member
You could arguably file a bug report and ask YYG to make draw_self() in future versions exit prematurely if no Sprite is assigned.
Not sure if masking the problem by having draw_self() just ignore the users assumption of a sprite being assigned, would be good though. I'd much rather get an error since it means my assumption of a sprite existing was incorrect.
 

TheouAegis

Member
Not sure if masking the problem by having draw_self() just ignore the users assumption of a sprite being assigned, would be good though. I'd much rather get an error since it means my assumption of a sprite existing was incorrect.
True, but people I would argue assume draw_self() is the functional replacement for the default draw event. Since the default exits prematurely if no sprite is set, arguably it stands to reason that the functional equivalent should also exit prematurely. And that's assuming the devs would even give a crap.
 
Top