Hey guys, I'm using a switch statement, which apparently uses multiple cases, when depending on the value, it should just perform one task. I'm using an enum and variable from my main player object and transfer the data to my "hand/gun" which only appears after pressing specific button. I've been looking into multiple topics, but can't find my issue, so anyway.
The player object
Creation Code, just setting up the variables:
Step event, simply just controlling the value for testing purposes:
The Hand object
Step Event, which controlls what eventually shoot out of it, I'll just paste everything in for context sake:
When beam value = 0, nothing fires. Value 1 fires both cases and value 2 only fires the plasma case. Why is value 1 doing both?
The player object
Creation Code, just setting up the variables:
GML:
enum beams {
none,
powerb,
plasma
}
global.beam = beams.none;
GML:
if (key_scroll_up){
global.beam +=1;
} else if (key_scroll_down){
global.beam -=1;
}
if (global.beam >=9) global.beam = 9;
if (global.beam <=0) global.beam = 0;
Step Event, which controlls what eventually shoot out of it, I'll just paste everything in for context sake:
GML:
x = obj_playerN.x-0.7;
y = obj_playerN.y-12.5;
image_angle = point_direction(x,y,mouse_x,mouse_y);
if (image_angle > 90) && (image_angle < 270){
image_yscale =-1;
} else {
image_yscale =1;
}
firingdelay = firingdelay -1;
recoil = max(0,recoil -1);
if (mouse_check_button_pressed(mb_left)) && (firingdelay < 0){
switch (global.beam){
case beams.powerb: {
recoil = 5;
firingdelay = 25;
with (instance_create_layer(x,y+7,"Bullets",oBeam)){
speed = 10;
direction = other.image_angle;
image_angle = direction;
audio_play_sound(PowerBeam,1,false);
break;
}
} case beams.plasma: {
recoil = 5;
firingdelay = 30;
with (instance_create_layer(x,y+7,"Bullets",oBeamPlasma)){
speed = 7;
direction = other.image_angle;
image_angle = direction;
audio_play_sound(BeamPlasma,1,false);
break;
}
} default: {
return 0;
}
}
if (mouse_check_button_pressed(mb_right)) && (firingdelay < 0){
recoil = 4;
firingdelay = 35;
with (instance_create_layer(x,y+7,"Bullets",oRocket)){
speed = 13;
direction = other.image_angle;
image_angle = direction;
audio_play_sound(RocketLaunch,1,false);
}
}
x = x - lengthdir_x(recoil,image_angle);
y = y - lengthdir_y(recoil,image_angle);
}
Last edited: