• 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!

GameMaker [RESOLVED] Affect multiples variables with arrays?

Hey,
Is there a way to affect all the variables/objects stored in an array?
I have read the GMS documentation and searched the forums but I have to admit I'm struggling to understand how to use arrays...

For example if i want to make something explode in multiple parts and affect theses parts, how should I do it?
In my mind it's something like this, but that doesn't work:

Code:
parts[1] = oHead
parts[2] = oBody
[...]

explosion = instance_create_layer(x,y,"layer",parts)
explosion.direction = ...
explosion.speed = ...
I know how to do this without arrays but that's a lot of code for nothing, so I'm asking to increase my workflow.

Thanks in advance!
 

FrostyCat

Redemption Seeker
Iterate through them with a loop.
Code:
parts[0] = oHead;
parts[1] = oBody;
//...

var parts_count = array_length_1d(parts);
for (var i = 0; i < parts_count; i++) {
  var explosion = instance_create_layer(x, y, "layer", parts[i]);
  explosion.direction = random(360);
  explosion.speed = random_range(6, 10);
  //...
}
 
M

maratae

Guest
Hey,
Is there a way to affect all the variables/objects stored in an array?
I have read the GMS documentation and searched the forums but I have to admit I'm struggling to understand how to use arrays...

For example if i want to make something explode in multiple parts and affect theses parts, how should I do it?
In my mind it's something like this, but that doesn't work:

Code:
parts[1] = oHead
parts[2] = oBody
[...]

explosion = instance_create_layer(x,y,"layer",parts)
explosion.direction = ...
explosion.speed = ...
I know how to do this without arrays but that's a lot of code for nothing, so I'm asking to increase my workflow.

Thanks in advance!
You can try looping through the array with a for loop.
 
Top