O
Oz Locke
Guest
Solved - Cannot use multiple conditions in a switch
As proivded below, changed to an if statement:
----------------------------------------------------------------------------------------------------------------------
I'm trying to build a switch statement to allow 8 directional movement (so straight off, if I'm doing it wrong, please tell me, though I'm trying trying to avoid the D&D)
The code seems right to me, but I think I'm missing a core concept, because it's throwing an error at compile. Any help with solving it would be appreciated
Here's the code:
And here's the error:
As proivded below, changed to an if statement:
Code:
if (keyboard_check(vk_up) ||keyboard_check(ord('W'))){
if(y > 2) y -= 2;
};
if (keyboard_check(vk_right) || keyboard_check(ord('D'))){
if(x < 1022) x += 2;
};
if (keyboard_check(vk_down) ||keyboard_check(ord('S'))){
if(y < 478) y += 6;
};
if (keyboard_check(vk_left) || keyboard_check(ord('A'))){
if(x > 6) x -= 6;
};
I'm trying to build a switch statement to allow 8 directional movement (so straight off, if I'm doing it wrong, please tell me, though I'm trying trying to avoid the D&D)
The code seems right to me, but I think I'm missing a core concept, because it's throwing an error at compile. Any help with solving it would be appreciated
Here's the code:
Code:
switch (keyboard_key)
{
//--ORTHOGINAL--
//up
case vk_up:
case ord('W'):
if(y > 2) y -= 2;
break;
//right
case vk_right:
case ord('D'):
if(x < 1022) x += 2;
break;
//down
case vk_down:
case ord('S'):
if(y < 478) y += 6;
image_index = 0;
image_speed = 0;
break;
//left
case vk_left:
case ord('A'):
if(x > 6) x -= 6;
image_index = 0;
image_speed = 0;
break;
//--DIAGONAL--
//(note that the image_speed code is used to make the bird glide)
//up + left
case vk_up && vk_left:
case ord('W') && ord('A'):
if(y > 2) y -= 2;
if(x > 6) x -= 6;
break;
//up + right
case vk_up && vk_right:
case ord('W') && ord('D'):
if(y > 2) y -= 2;
if(x < 1022) x += 2;
break;
//down + left
case vk_down && vk_left:
case ord('S') && ord('A'):
if(y < 478) y += 6;
if(x > 6) x -= 6;
image_index = 0;
image_speed = 0;
break;
//down + right
case vk_down && vk_right:
case ord('S') && ord('D'):
if(y < 478) y += 6;
if(x < 1022) x += 2;
image_index = 0;
image_speed = 0;
break;
};
Final Compile...Error : gml_Object_obj_bird_Key_ANYKEY_1(53) : duplicate case statement found
Error : gml_Object_obj_bird_Key_ANYKEY_1(54) : original here
Error : gml_Object_obj_bird_Key_ANYKEY_1(45) : duplicate case statement found
Error : gml_Object_obj_bird_Key_ANYKEY_1(46) : original here
Error : gml_Object_obj_bird_Key_ANYKEY_1(39) : duplicate case statement found
Error : gml_Object_obj_bird_Key_ANYKEY_1(40) : original here
Error : gml_Object_obj_bird_Key_ANYKEY_1(33) : duplicate case statement found
Error : gml_Object_obj_bird_Key_ANYKEY_1(34) : original here
Error : gml_Object_obj_bird_Key_ANYKEY_1(54) : original here
Error : gml_Object_obj_bird_Key_ANYKEY_1(45) : duplicate case statement found
Error : gml_Object_obj_bird_Key_ANYKEY_1(46) : original here
Error : gml_Object_obj_bird_Key_ANYKEY_1(39) : duplicate case statement found
Error : gml_Object_obj_bird_Key_ANYKEY_1(40) : original here
Error : gml_Object_obj_bird_Key_ANYKEY_1(33) : duplicate case statement found
Error : gml_Object_obj_bird_Key_ANYKEY_1(34) : original here
Last edited by a moderator: