• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

(SOLVED) Changing a group of instances with the same pre-condition

Hi everyone!
I have an object that is spread across a room,
meaning there are many instances of that object.

In the instances creation code (not in the object create event, but in the instances creation code in the room editor) I gave "groups" of these instances a specific value.
Some of these instances have a variable numbered "1", others "2", others "3".
Depending on that number, when I make my player do a certain action,
all instances of the same number need a change. The others must be left alone.

Generic example that exactly points out what i want to do:
Say out of 99 instances, 33 have number 1, 33 have number 2, 33 have number 3. If the player
clicks on a SINGLE instance with number 1, all instances with number 1 must be accessed and be given a change, while leaving all instances with number 2 and 3 alone.

Is there a certain way of going about with this?

I know I'm not being too clear here, as showing code would probably be a bit confusing, as I'm just trying to get a very general idea of how to do this. So in order to make my question clear without showing a bunch of code, let me just say I'm searching for a principle, a way of doing something. Basically what I want is:

How to access multiple instances of the SAME object, but ONLY those instances of that object that have the same pre-condition in their own specific create event. These instances that need to be changed, have been given the same value for a variable in their INSTANCE CREATION CODE, so not in their CREATE EVENT.
Changing one of these similar instances should change ONLY those instances with the same variable-value.

I hope this question is clear, as I think it could help me big-time and it might even be an interesting question to ask for who-ever stumbles upon this thread.

I just have this feeling a simple for-loop could do the trick, but I think I'm missing the correct knowledge about instance functions and logic here.
 
Use a with statement and inside that check the variable and then update that instance if it meets the condition.

Something like this:
Code:
with (obj_whatever) {
  if (instance_variable == 1) {
    //set another variable on that instance.  eg: instance_var2 = 35;
  }
}
That should loop through all of the instances of that object (obj_whatever) and then check the instance variable called "instance_variable" to see if it has the value of 1, and if so do whatever else you want it to do.
 
Use a with statement and inside that check the variable and then update that instance if it meets the condition.

Something like this:
Code:
with (obj_whatever) {
  if (instance_variable == 1) {
    //set another variable on that instance.  eg: instance_var2 = 35;
  }
}
That should loop through all of the instances of that object (obj_whatever) and then check the instance variable called "instance_variable" to see if it has the value of 1, and if so do whatever else you want it to do.
Wow that simple huh? I might have been staring at my screen for far too long xD Thanks A LOT. Sometimes even the simple things become completely out of reach. I think I might need a little break at this point. You're a lifesaver! It works exactly like I want to now :) Now I can rest easy :p
 
Top