Legacy GM [SOLVED] Change particle colours with a button press



Howdy folks.

I've got it so the player can switch states when he presses 1, 2, 3 or 4 which changes the sprite colour and attack animation. That's all hunky dory. What I've now done is attach a particle system to the player object (so it leaves a trail behind them), which again works fine.

However, when the player changes states the particles remain one colour - I'd like to have it so it also changes colour (eg 1 = blue, 2 = green, etc). I thought adding a variable (RexColour) would work, with this added in each state script (eg RexColour = c_blue), so that once the states change the particle system then references the new variable details.

Except this variable is only referenced if I put it in the same Create Event as the particle system (otherwise it can't find the variable; it also still ignores the new variable reference when states/scripts are then changed). I also tried adding RexColour into the button press events but the variable's ignored then as well).

Basically, the game only seems to reference the RexColour variable in the player object Create Event.

What on earth am I doing wrong? Cheers for any help! If I should paste any other code, let me know :)
Here's the object create code:

state = scr_rex_invincible; //Player (Rex) starts off invincible then presses 1 - 4 to change states
RexColour = c_white;

//particle system
partFairyDust_sys = part_system_create();

partFairyDust = part_type_create();
part_type_size(partFairyDust, 1,2,0,0);
part_type_colour1(partFairyDust, RexColour); //RexColour should change depending on state
part_type_alpha2(partFairyDust, 1,0);
part_type_speed(partFairyDust, 0.8, 1, 0,0);
part_type_direction(partFairyDust, 0, 359,0,0);
part_type_blend(partFairyDust, 1);
part_type_life(partFairyDust, room_speed*2, room_speed*4);

//Particle emitter
partFairyDust_emit = part_emitter_create(partFairyDust_sys);

//These tie in to Step code that makes particles only form when player object is moving
old_x = 0;
old_y = 0;


I'm not super experienced with particles, so I'm not sure if this will work:

Where you're trying to change the RexColor variable, do a full part_type_color1 command instead.

I don't know if you can change particle properties on the fly like that though, so if it doesn't work, you'll have to create four identical particles with different colors, and store the name of the correct particle in a variable, and ise rhat variable when creating your particles .


In order to make particle_type_colour1() change the particle type's colour, you need to call it in the Step event.

LastColour = c_white;
RexColour = c_white;
if (LastColour != RexColour) {
   particle_type_colour1(partFairyDust, RexColour);
   LastColour = RexColour;


Yes! All I then needed to do was put RexColour in each state script and it works like a charm. Thanks a lot!