Jump to content


Photo

Destroy one object but not all


  • Please log in to reply
12 replies to this topic

#1 junky1

junky1

    GMC Member

  • New Member
  • 96 posts

Posted 07 May 2012 - 07:04 AM

Okay. I'm almost finished with the game I'm working on but I have a huge problem (maybe not for some), but I'm not very experienced with GML. I've always used drag & drop for the most part.

K....so I have all these blocks (all the same object) and I want them to crumble one by one as I walk across them. So HOW do I destroy one block without destroying ALL the blocks in the room?

I will give credit to you on my game for helping me with this....cause this is the last problem I am facing for this game (i think). Thanks.
  • 0

#2 Ysmor

Ysmor

    GMC Member

  • New Member
  • 84 posts
  • Version:GM8

Posted 07 May 2012 - 07:06 AM

maybe, put some code in the block object.
When it collides with the player use this code:
instance_destroy();
Hope that helped.

- Ysmor
  • 0

#3 junky1

junky1

    GMC Member

  • New Member
  • 96 posts

Posted 07 May 2012 - 07:16 AM

maybe, put some code in the block object.
When it collides with the player use this code:

instance_destroy();
Hope that helped.

- Ysmor


That would destroy all the blocks in the room i believe. Cause all the blocks in my room are the same object. Which is my problem. How do I destroy just one of them without ALL of them being destroyed?
  • 0

#4 Lightang3l

Lightang3l

    GMC Member

  • GMC Member
  • 1284 posts
  • Version:GM:Studio

Posted 07 May 2012 - 07:19 AM

In the bloc object:
Create Event:
crumble = 0
Collision with player Event:
crumble = 1
Step Event:
if crumble = 1 instance_destroy()  //or whatever you want

instance_destroy() will destroy that instance only, as it's name suggests...
  • 0

#5 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 07 May 2012 - 07:31 AM

In the bloc object:
Create Event:

crumble = 0
Collision with player Event:
crumble = 1
Step Event:
if crumble = 1 instance_destroy()  //or whatever you want

instance_destroy() will destroy that instance only, as it's name suggests...

that should do it because every object has its own id number!Posted Image
making each object it's own and parents connect them basically!
  • 0

#6 junky1

junky1

    GMC Member

  • New Member
  • 96 posts

Posted 07 May 2012 - 07:37 AM

In the bloc object:
Create Event:

crumble = 0
Collision with player Event:
crumble = 1
Step Event:
if crumble = 1 instance_destroy()  //or whatever you want

instance_destroy() will destroy that instance only, as it's name suggests...


Hmm....that didn't work for me. Crap. Thanks anyway. Any other suggestions?

Edit: Wait. Am I supposed to put something in those ()? I tried putting the name of my object but it showed it was an invalid code. So I just left it blank.

Edited by junky1, 07 May 2012 - 07:40 AM.

  • 0

#7 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 07 May 2012 - 07:40 AM


In the bloc object:
Create Event:

crumble = 0
Collision with player Event:
crumble = 1
Step Event:
if crumble = 1 instance_destroy()  //or whatever you want

instance_destroy() will destroy that instance only, as it's name suggests...


Hmm....that didn't work for me. Crap. Thanks anyway. Any other suggestions?

what do you mean?!
it should have worked!
  • 0

#8 TDWP_FTW

TDWP_FTW

    GMC Member

  • GMC Member
  • 296 posts
  • Version:GM:Studio

Posted 07 May 2012 - 07:41 AM

I'm not sure if this was ever changed, but you'll have to do the instance_destroy code like this:

with self {instance_destroy()}

It never worked for me without the "with self" part, as it would give errors, so IDK.
  • 0

#9 junky1

junky1

    GMC Member

  • New Member
  • 96 posts

Posted 07 May 2012 - 07:42 AM



In the bloc object:
Create Event:

crumble = 0
Collision with player Event:
crumble = 1
Step Event:
if crumble = 1 instance_destroy()  //or whatever you want

instance_destroy() will destroy that instance only, as it's name suggests...


Hmm....that didn't work for me. Crap. Thanks anyway. Any other suggestions?

what do you mean?!
it should have worked!


Do I put something in the ()? Cause I just left it blank. I tried to put the name of my obj in there but it showed it was an invalid code. ??
  • 0

#10 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 07 May 2012 - 07:47 AM




In the bloc object:
Create Event:

crumble = 0
Collision with player Event:
crumble = 1
Step Event:
if crumble = 1 instance_destroy()  //or whatever you want

instance_destroy() will destroy that instance only, as it's name suggests...


Hmm....that didn't work for me. Crap. Thanks anyway. Any other suggestions?

what do you mean?!
it should have worked!


Do I put something in the ()? Cause I just left it blank. I tried to put the name of my obj in there but it showed it was an invalid code. ??

you don't put nothing but the parentheses in front of instance destroy!
also put it like this to cause less probs:
if crumble = 1 with self {instance_destroy()}

  • 0

#11 Jsd1019

Jsd1019

    GMC Member

  • GMC Member
  • 29 posts
  • Version:GM8

Posted 07 May 2012 - 07:47 AM




In the bloc object:
Create Event:

crumble = 0
Collision with player Event:
crumble = 1
Step Event:
if crumble = 1 instance_destroy()  //or whatever you want

instance_destroy() will destroy that instance only, as it's name suggests...


Hmm....that didn't work for me. Crap. Thanks anyway. Any other suggestions?

what do you mean?!
it should have worked!


Do I put something in the ()? Cause I just left it blank. I tried to put the name of my obj in there but it showed it was an invalid code. ??

Don't put anything inside the ().
  • 0

#12 junky1

junky1

    GMC Member

  • New Member
  • 96 posts

Posted 07 May 2012 - 07:57 AM

Crap! None of these things are working unfortunatly. It may be because I based my game around an isometric example that involves a bunch of depth and height codes, that I only somewhat understand, since I usually code with D&D. It may be conflicting with the existing height and ground codes. IDK. I can't even get any of my blocks to destroy. Even using D&D. I don't know what the deal is.
  • 0

#13 junky1

junky1

    GMC Member

  • New Member
  • 96 posts

Posted 07 May 2012 - 08:04 AM

Okay! Your code did work, just not the way I wanted it to. See....I have height to my blocks, and my character jumps onto the blocks. Well when I jump up to the block the code doesn't work. But if I just move to the block and run into it that way.....It does work. And it destroys one at a time. But it's not working the way I want, but I'm sure I can figure it out from here. THANKS!

I'm giving you guys credit in my game. Big help. Thanks!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users