Pages: 1
Author Topic: How to check instance count + other  (31,741 Views)
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Posted on: May 16, 2014, 05:47:08 AM
2 questions.
1)
I noticed there is only instance_count, which counts the total instances in a room.  YET when you look in the D&D, the panel allows you to check instances only of particular objects.  Same for GMS.

Since I cannot stand D&D anymore and do everything by code, could someone please tell me how I can do the equivalent of the action check instance count for a specific object ?

Example, I have a controller object in a room, what if I wanted it to check number of instances of a specific object in the room, how would I go about....

if I use the if (instance_count), that checks the total active instances in a room !

---------------------------------------------------

2) Destroying individual instances

Now I know how to do this by having the object itself detect collision with another and calling a destroy function, it will destroy self (the instance only, not all the object).

What if I want to control this from another object.

Example, object A shoots Objects B, but collision against object b is checked in A.  B is a solid object.

So in Object A I would use

if (place_meeting(x,y,obj_b)
...
...

What should I do next ?

If I use

with (obj_b)
{
destroy_instance();
}

it will kill all instances of object b !
I want only the instance of object b that was hit by object a to be killed.

I can do this with the D&D object kill object, in the panel select other.....  This will cause whatever object a was hit to be killed.  How the hell can I replicate this with GML?

I tried using other,self, etc. does not work.

This is the same in GMS.  I find it ridiculous I have
to use D&D and cannot do this in GML.

Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #1 Posted on: May 16, 2014, 08:30:33 AM
QuoteSince I cannot stand D&D anymore and do everything by code, could someone please tell me how I can do the equivalent of the action check instance count for a specific object ?
Read the manual(s): http://enigma-dev.org/docs/Wiki/Instance_number
http://docs.yoyogames.com/source/dadiospice/002_reference/objects%20and%20instances/instances/instance%20functions/instance_number.html

Quoteit will kill all instances of object b !
Then you need to get the id of the object you hit. If you use a collision event (instead of a "place_meeting") then you can use "other". If you want to check collision manually in step event, then you must use a collision function like "instance_place" (again, manual(s): http://enigma-dev.org/docs/Wiki/Instance_place
http://docs.yoyogames.com/source/dadiospice/002_reference/objects%20and%20instances/instances/instance%20functions/instance_place.html).
inst = instance_place(x, y,obj_b);
if (inst != noone)) {
  with (inst) instance_destroy();
}
I think for some time we also supported an overload for instance_destroy(), so you could do this:
instance_destroy(inst);But I don't know if we kept it (can't test it now either).

QuoteThis is the same in GMS.  I find it ridiculous I have
to use D&D and cannot do this in GML.
You can do all of that. Just read the manual or search for example. You can of course ask here as well. In GM for a long time the only thing that you could do with Events/D&D but not with code, was checking the mouse wheel. That is the only thing I know which was impossible in pure GML. The rest should be.
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Reply #2 Posted on: May 16, 2014, 05:43:51 PM
Wow ! I can't believe I missed this!  Trust me, I read the manuals all the time.  I can't believe I missed the instance_number......  When looking through manual I made a search for instance_ and for some odd reason I only saw instance_count.  Thanks !

Regarding the instance_place, never thought of that either.  Guess I have to go deeper into the manual.
Pages: 1