• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Can someone help me? Im new to Gms 2.

LamaMate

Member
I got a problem, and i dont know how to fix it. I got this error code :
___ ############################################################################################ ERROR in action number 1 of Step Event1 for object oSGun: Unable to find any instance for object index '9' name 'oPlayer' at gml_Object_oSGun_Step_1 (line 2) - x = oPlayer.x; ############################################################################################ gml_Object_oSGun_Step_1 (line 2)

I have programmed a weapon. Then I programmed a boss and if you defeat him, you get a stronger weapon. If you collect it and then die with the weapon in your hand, the game hangs up. But the funny thing is, with the other one it works. (Of course with the help of a video)

I would be very happe if someone can help me.
 

chamaeleon

Member
If you collect it and then die with the weapon in your hand, the game hangs up.
Without any code shown to help others understand what your code is doing, does "die" imply you destroy your instance of oPlayer, meaning that using oPlayer.x or any other variable becomes invalid because no instance of that object type exist in your game at that point?
 

LamaMate

Member
this is the code, it is the same code for both, i just improved the values of the weapon.

//Gun Physiks
x = oPlayer.x;
y = oPlayer.y+10;


if (oPlayer.controller == 0)
{
image_angle = point_direction(x,y,mouse_x,mouse_y);
}
else
{
var controllerh = gamepad_axis_value(0,gp_axisrh);
var controllerv = gamepad_axis_value(0,gp_axisrv);
if (abs(controllerh) > 0.2) || (abs(controllerv) > 0.2)
{
controllerangle = point_direction(0,0,controllerh,controllerv)
}
image_angle = controllerangle;
}



firingdelay = firingdelay - 1;

// Shoot system
if ((mouse_check_button(mb_left)) || gamepad_button_check(0,gp_shoulderrb)) && (firingdelay < 0)
{
recoil = 4;
firingdelay = 2;
ScreenShake(2,10);
audio_sound_pitch(snShot,random_range(0.5,1.5));
audio_play_sound(snShot,5,false);

with (instance_create_layer(x,y,"Bullet",oBullet))
{
speed = 30;
direction = other.image_angle + random_range(-3,3)
image_angle = direction;
}

with (oPlayer)
{
gunkickx = lengthdir_x(1.5, other.image_angle-180);
gunkicky = lengthdir_y(1, other.image_angle-180);
}
}

recoil = max(0,recoil - 1);

x = x - lengthdir_x(recoil,image_angle);
y = y - lengthdir_y(recoil,image_angle);

if (image_angle > 90) && (image_angle < 270)
{
image_yscale = -1;
}
else
{
image_yscale = 1;
}

if instance_exists(oGun) and keyboard_check_pressed(ord("Q"))
{

instance_destroy();
instance_create_layer(oPlayer.x+10,oPlayer.y-10,"Gun",oGunPickup);
}
 

LamaMate

Member
so this is now the code of the standard weapon. the difference to the stronger one is the "oSGun" and the "oSGunPickup" is everywhere instead of "oGun" and "oGunPickup
 

LamaMate

Member
when the player dies a dead object appears, then an animation appears and then the room is restarted. but when the dead object appears the game hangs
 

chamaeleon

Member
what do you mean? there is no code to destroy the player?
If you put
GML:
show_debug_message("Number of oPlayer instances = " + string(instance_number(oPlayer));
before your x = oPlayer.x line that causes the crash, what is the output? If you expect one instance, and the ouput is 1, you have not destroyed it. If you expect one instance but the output is 0, you have destroyed it.
 

chamaeleon

Member
ok its 0, but i dont know why
Add a Destroy event to oPlayer, and put some statement in it, perhaps show_debug_message("I'm being destroyed");, and put a breakpoint on that line, run the game in debug mode, and look at the callback stack to see what event/script/function calls instance_destroy() and which line that call is on.
 

LamaMate

Member
so i make a destroy event at the oPlayer with the command "show_debug_message("I'm being destroyed");" and start the game in debugg mode and see in which line the error is
 

chamaeleon

Member
so i make a destroy event at the oPlayer with the command "show_debug_message("I'm being destroyed");" and start the game in debugg mode and see in which line the error is
Yes, as long as you have also clicked just to the left of the line number in the code editor by that line to toggle on a red breakpoint marker (or the debugger won't stop and give you the call stack).
 

LamaMate

Member
but it doesn't say anything else, it just says that there is something in the "show_debug_message("I'm being destroyed");", but I don't see anything else
 

chamaeleon

Member
but it doesn't say anything else, it just says that there is something in the "show_debug_message("I'm being destroyed");", but I don't see anything else
Did you click the debug button to run instead of the run button? Also, do read in the manual about all these things.
 

chamaeleon

Member
yeah i run it in the debugg mode, i pressed the right button
Are you saying that you have the breakpoint red marker enabled on the show_debug_message(), you run in debug mode, and you see the message instead of the debugger stopping execution on that line?
 

chamaeleon

Member
Then I will just recommend watching
to see if there's anything in your workflow you have done incorrectly when using the debugger.
 
Top