Jump to content


Photo

Changing other instances in an event depending on the criteria.


Best Answer cdrdub8, 28 March 2016 - 10:01 PM

You can access all instance that are in the room by using the special keyword all.

If you use it with the [b]with statement[b/] you can effectively check all instances.

 

example, let's say when I click on a button, I want to make all instances that are in the right half of the

room to become semi-transparent, I would do this:

// Left Mouse Button Pressed on obj_button
 
with( all ) {
    // First, if the instance is this object ( the button ) then ignore
    if( other == id ) continue;
 
    // Next, we check if the instance is inside the right half of the room
    if( x >= room_width/2 ) {
        // Finally, we make this instance semi-transparent
        image_alpha = 0.5;
    }
}

 

The above code will effectlively set all the instances in the right half of the room to be semi-transparent.

Note that even if the button we click on is in the right half, it won't become semi-transparent

because we make sure the instance isn't the button before doing anything.

 

Hope this helps ~

- Cdrdub8

Go to the full post


  • Please log in to reply
1 reply to this topic

#1 qman0114

qman0114

    GMC Member

  • New Member
  • 1 posts
  • Version:GM:Studio

Posted 28 March 2016 - 09:09 PM

I am fairly new to GameMaker Studio and I am trying to figure out how to do something. Basically when I click on an object i want it to look through all of the instances created and if one of them meets the criteria I have set (Such as the coordinates), then it will change for that instance one of the variables. Sorry if I explained the situation poorly.


  • 0

#2 cdrdub8

cdrdub8

    GMC Member

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

Posted 28 March 2016 - 10:01 PM   Best Answer

You can access all instance that are in the room by using the special keyword all.

If you use it with the [b]with statement[b/] you can effectively check all instances.

 

example, let's say when I click on a button, I want to make all instances that are in the right half of the

room to become semi-transparent, I would do this:

// Left Mouse Button Pressed on obj_button
 
with( all ) {
    // First, if the instance is this object ( the button ) then ignore
    if( other == id ) continue;
 
    // Next, we check if the instance is inside the right half of the room
    if( x >= room_width/2 ) {
        // Finally, we make this instance semi-transparent
        image_alpha = 0.5;
    }
}

 

The above code will effectlively set all the instances in the right half of the room to be semi-transparent.

Note that even if the button we click on is in the right half, it won't become semi-transparent

because we make sure the instance isn't the button before doing anything.

 

Hope this helps ~

- Cdrdub8


  • 0

I am building awesomeness, wait for it!