-2
\$\begingroup\$

I basically need that, changing a variable of all the instance (all of the same object) around another instance (another, or the same object).

I have tried with collision_rectangle but it doesn't work.

Edit: This gives a better explication of what i want to do

ObjA = Object that inicially changes ObjB variable

ObjB= Object that is produced massively

ObjC= Object that produces ObjB

What im doing(or trying to do):

  1. ObjA Appears.
  2. ObjA moves down, and check for any ObjB instance
  3. If it finds a ObjB instance, change the variable "chain" from "false" to "true". If the ObjA gets out of the room, without finding any instance, delete it
  4. (In ObjB) If chain = true && any other ObjB instance near{ other ObjB chain = true} 5.(In ObjB).If Obj chain = true && instance of ObjC near{ with (objC){ //Do something, for example, create ObjD in the same position and erase itself } }

What i want to do is change the objC that emmits ObjB, To ObjD that produce ObjE. And ObjD will work the same as objC but is going to produce ObjE. Its like a cycle

\$\endgroup\$
  • \$\begingroup\$ Could you add a code sample and more detail? \$\endgroup\$ – ChrisUC Feb 23 '16 at 10:25
  • \$\begingroup\$ The question isn't clear enough for me... \$\endgroup\$ – DH. Feb 23 '16 at 10:54
0
\$\begingroup\$

By "around" I am assuming that you want to change the variable of the target objects a certain distance to the flag object, now, let the object whose variable will change be obj_A, and the object which will make obj_A change variable be obj_B. Now try the following:

//this is run in obj_A
if distance_to_object(obj_B)<100
{
variable1+=1
}

Of course the 100, "variable1" and "+=1" are just examples. If you want the region of space where changes take place to be rectangular, try this:

//this is run in obj_A
if abs(x-obj_B.x)<50 and abs(y-obj_B.y)<50
{
variable1+=1
}

With regards to the expansion of the question, I am not sure what is described here. I would suggest giving some background information on what the game is like and why are the objects doing what they are doing, perhaps given the objects names like "bullet" "player" etc. so it is more recognizable.

I would suggest, in case you are not aware, to use the "with" command, which allows an instance to temporarily make another instance or all instances of another object do something. Examples:

In obj_Explosion:

if instance_exists(obj_Enemy) 
with(obj_Enemy)
{
    if distance to object (other)<100
    {
    HP-=10
    }

}
with (instance_nearest(x,y,obj_Enemy))
{
instance_destroy()
}

The annotate version of the above is this:

if instance_exists(obj_Enemy) //the object "obj_Explosion" is checking if there are any enemies.
with(obj_Enemy)  //the "Explosion" now asks all the "Enemies" to do the following:
{
    if distance to object (other)<100 //the enemies each check if it is close to the "other" instance, in this case, the explosion.
    {
    HP-=10 //if the enemy is close, it takes damage from its own "HP"
    }

} //here the section in which the enemy is doing things is over, back to the "Explosion"
with (instance_nearest(x,y,obj_Enemy)) //Now the explosion checks for the particular enemy that is the closest to itself
{
instance_destroy() //...and destroys it
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.