Jump to content


Photo

Instance_destroy()


  • Please log in to reply
16 replies to this topic

#1 dado320

dado320

    GMC Member

  • New Member
  • 12 posts

Posted 16 March 2009 - 07:12 PM

Hi, sorry to post a new topic but i couldent finde any a working exempel....
okay my problem is that i got this code :
{
  // check whether you can shoot
  if (not can_shoot) exit;
  can_shoot = false;
  // show the animation and play the sound
  image_speed = 0.4;
  image_index = 0;
  sound_play(machingun);
  // determine what you hit
if place_meeting( x+x, y+y,obj_monster1);
instance_destroy(other);
}

but i got this error:
___________________________________________
FATAL ERROR in
action number 4
of Mouse Event for Glob Left Pressed
for object Gun:

COMPILATION ERROR in code action
Error in code at line 11:
instance_destroy(other);

at position 24: Wrong number of arguments to function or script.

i know it's the instance_destroy that doesent work but why....
any help would be appricatied :(

and agine sorry to ask this n00b question xD
  • 0

#2 Maxi06

Maxi06

    GMC Member

  • New Member
  • 276 posts

Posted 16 March 2009 - 07:13 PM

Change it to
with(other)
{
instance_destroy();
}
that should work.
  • 0

#3 chaz13

chaz13

    GMC Member

  • GMC Member
  • 3827 posts
  • Version:Unknown

Posted 16 March 2009 - 07:14 PM

Change it to:

with(other)
instance_destroy()

instance_destroy() has no arguments.
  • 0

#4 dado320

dado320

    GMC Member

  • New Member
  • 12 posts

Posted 16 March 2009 - 07:14 PM

Change it to
with(other)
{
instance_destroy();
}
that should work.

okay i will try and if it works THANKS :(
  • 0

#5 dado320

dado320

    GMC Member

  • New Member
  • 12 posts

Posted 16 March 2009 - 07:17 PM

okay now i can start the game agine... but the code will only destroy me HUD... not the enemy :(
  • 0

#6 Maxi06

Maxi06

    GMC Member

  • New Member
  • 276 posts

Posted 16 March 2009 - 07:18 PM

is the code placed in a collision event?
  • 0

#7 chaz13

chaz13

    GMC Member

  • GMC Member
  • 3827 posts
  • Version:Unknown

Posted 16 March 2009 - 07:19 PM

Oh, you can't use other like that.

Use this:

{
  // check whether you can shoot
  if (not can_shoot) exit;
  can_shoot = false;
  // show the animation and play the sound
  image_speed = 0.4;
  image_index = 0;
  sound_play(machingun);
  // determine what you hit
var c;
c=instance_place( x+x, y+y,obj_monster1);
if (c){
with(c)
instance_destroy();
}
}

Edited by chaz13, 16 March 2009 - 07:30 PM.

  • 0

#8 dado320

dado320

    GMC Member

  • New Member
  • 12 posts

Posted 16 March 2009 - 07:23 PM

okay well maby i should tell you some stuff also XD sorry i thougt the code would work
before i used this code that doesent need a bullet obj
{
  // check whether you can shoot
 if (not can_shoot) exit;
  can_shoot = false;
  // show the animation and play the sound
  image_speed = 0.7;
  image_index = -1;
  sound_play(machingun);
  // determine what you hit
  var xx, yy, ii;
  xx = global.camx;
  yy = global.camy;
  repeat (50)
  {
	xx += 4*global.camcos;
	yy -= 4*global.camsin;
	ii = instance_position(xx,yy,obj_wall_basic);
	if (ii == noone) 
	{
	  ii = instance_position(xx,yy,obj_monster_basic);
	  if (ii == noone) continue;
	  with (ii) instance_destroy();
	  break;
	}
	if object_is_ancestor(ii.object_index,obj_plant_basic) continue;
	if (ii.object_index == obj_barrel) 
	   with (ii) instance_destroy();
	break;
  }
}
but when i used it the freaking enemy would die so.. i chaged it a bit cuz i thout i could first check whatever the enemy is infront off me and then kill it ... sorry i'm nnot so good to tell detiles XD sorry

Oh, you can't use other like that.

Use this:

{
  // check whether you can shoot
  if (not can_shoot) exit;
  can_shoot = false;
  // show the animation and play the sound
  image_speed = 0.4;
  image_index = 0;
  sound_play(machingun);
  // determine what you hit
var c;
c=instance_place( x+x, y+y,obj_monster1);
if (c){
with(other)
instance_destroy();
}
}


  • 0

#9 Katuko

Katuko

    GMC Member

  • GMC Member
  • 4886 posts

Posted 16 March 2009 - 07:25 PM

Wouldn't that be with © { instance_destroy(); } ?
  • 0

#10 dado320

dado320

    GMC Member

  • New Member
  • 12 posts

Posted 16 March 2009 - 07:26 PM

emm what?
  • 0

#11 chaz13

chaz13

    GMC Member

  • GMC Member
  • 3827 posts
  • Version:Unknown

Posted 16 March 2009 - 07:29 PM

Yeah, my mistake. Forgot to change that.
  • 0

#12 DarkSentinel

DarkSentinel

    GMC Member

  • New Member
  • 1965 posts

Posted 16 March 2009 - 07:33 PM

It's supposed to be
with ( c ) { instance_destroy(); }
Katuko didn't put spaces so the forum replaced it with the copyright symbol ©.

Edited by DarkSentinel, 16 March 2009 - 07:34 PM.

  • 0

#13 dado320

dado320

    GMC Member

  • New Member
  • 12 posts

Posted 16 March 2009 - 07:34 PM

okay

It's supposed to be

with ( c ) { instance_destroy(); }
Katuko didn't put spaces so the forum replaced it with the copyright symbol �.


  • 0

#14 dado320

dado320

    GMC Member

  • New Member
  • 12 posts

Posted 16 March 2009 - 07:38 PM

okay, but still the code dosent work, i dont know why but in my other game i can kill the enemys with the same code
  • 0

#15 DarkSentinel

DarkSentinel

    GMC Member

  • New Member
  • 1965 posts

Posted 16 March 2009 - 07:42 PM

Probably because you are destroying the enemy at the position x+x and y+y. Why that position? Don't you want something like mouse_x and mouse_y?
  • 0

#16 dado320

dado320

    GMC Member

  • New Member
  • 12 posts

Posted 16 March 2009 - 07:49 PM

Okay, i fell i dident explaine it to you corectly so i will try to do an other try.

1. i got this code in the global.left.pressed(mouse):
{
  // check whether you can shoot
 if (not can_shoot) exit;
  can_shoot = false;
  // show the animation and play the sound
  image_speed = 0.7;
  image_index = -1;
  sound_play(machingun);
  // determine what you hit
  var xx, yy, ii;
  xx = global.camx;
  yy = global.camy;
  repeat (50)
  {
	xx += 4*global.camcos;
	yy -= 4*global.camsin;
	ii = instance_position(xx,yy,obj_wall_basic);
	if (ii == noone) 
	{
	  ii = instance_position(xx,yy,obj_monster_basic);
	  if (ii == noone) continue;
	  with (ii) { instance_destroy(); };
	  break;
	}
	if object_is_ancestor(ii.object_index,obj_plant_basic) continue;
	if (ii.object_index == obj_barrel) 
	   with (ii) instance_destroy();
	break;
  }
}
2.In my other game i stole the code from i can kill the enemys with this code...
3.just yell if you dont understand i'll try to send you the .gmc file :(
  • 0

#17 Botyto

Botyto

    GMC Member

  • GMC Member
  • 1247 posts

Posted 16 March 2009 - 08:00 PM

if place_meeting( x+x, y+y,obj_monster1);
instance_destroy(other);

Impossible! you can't be intouch with something at that position :(
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users