GameMaker How to change the value of all objects inside an array

E

E.M.I

Guest
Hey GameMaker community! So I'm trying to make a basic script that assures that shadows will always appear in front of the player but always appear behind the object they're the shadow of. For this I'm making code that, when the shadow collides with the player, changes the depth value of the shadow and the object the shadow comes from to be higher than the player's.
However, I don't want to make every single object's depth value higher, so I thought to create an array where all the objects are stored that I can call on. However, for that to work, I need to be able to change the depth value of all objects inside the array. Is this possible? (something like shadow_depth[all] maybe). Thanks a lot! To help a bit, here's what the code would look like.

(Inside the collide event with the player object, obj_eitim)

Code:
depth = (obj_eitim.depth - 1);
shadow_depth[all] = (obj_eitim.depth -1);
 

FrostyCat

Redemption Seeker
Use a for loop.
Code:
depth = obj_eitim.depth-1;
for (var i = array_length_1d(shadow_depth)-1; i >= 0; i--) {
  shadow_depth[i] = depth;
}
 
T

Taddio

Guest
You will need to get the array length, and run a loop as long as the array. You will definately be able to change depth with this, but keep an eye on the layers as well, if you have a couple of them, they have their own depth, so it MIGHT mess some things if you would, for example, set depth to 0 for everything (as some instances could be on a layer with some other depth), but simply using relatives values like depth += 1;, like I guess is what you'll be doing, there should he no problem.

Edit: Ninjad!
 
E

E.M.I

Guest
Use a for loop.
Code:
depth = obj_eitim.depth-1;
for (var i = array_length_1d(shadow_depth)-1; i >= 0; i--) {
  shadow_depth[i] = depth;
}
You will need to get the array length, and run a loop as long as the array. You will definately be able to change depth with this, but keep an eye on the layers as well, if you have a couple of them, they have their own depth, so it MIGHT mess some things if you would, for example, set depth to 0 for everything (as some instances could be on a layer with some other depth), but simply using relatives values like depth += 1;, like I guess is what you'll be doing, there should he no problem.

Edit: Ninjad!
Thanks you too! I'll be looking into for loops and the such.
 
Top