I
Inspiratium Entertainment
Guest
Delay when selecting 1st menu item via switch case.
Hey all,
So, I have a rudementary menu setup for my turn based fight system. When I select the first option by pressing enter, "Fight" which is controlled by switch case 2, I have to press enter multiple times before it seems to register the input?
If I go down and select "Flee" (which is just assigned to case 0 and ends the game) it works everytime on the first press. Have I made some error somewhere that you can see, or, is this due to poor optimization? PLEASE HELP, I don't have any idea what I did wrong here and it's probably something stupidly simple that I stupidly missed.
Step Event
Hey all,
So, I have a rudementary menu setup for my turn based fight system. When I select the first option by pressing enter, "Fight" which is controlled by switch case 2, I have to press enter multiple times before it seems to register the input?
If I go down and select "Flee" (which is just assigned to case 0 and ends the game) it works everytime on the first press. Have I made some error somewhere that you can see, or, is this due to poor optimization? PLEASE HELP, I don't have any idea what I did wrong here and it's probably something stupidly simple that I stupidly missed.
Step Event
Code:
//Menu control logic
//menu transitions from right of screen inward
menu_x += (menu_x_target - menu_x) / menu_speed;
//Keyboard menu controls
if (menu_control == true) {
if (keyboard_check_pressed(ord("W"))) {
menu_cursor++;
if (menu_cursor >= menu_items) {
menu_cursor = 0;
}
}
if (keyboard_check_pressed(ord("S"))) {
menu_cursor--;
if (menu_cursor < 0) {
menu_cursor = menu_items - 1;
}
}
if (keyboard_check_pressed(vk_enter)) {
menu_committed = menu_cursor;
menu_control = false;
}
}
//perform committed menu action
if (menu_committed != -1) {
switch(menu_committed) {
case 2: default:
//get random number for accuracy check
playerAccuracy = irandom(100);
if (playerAccuracy <= 10) {
playerCanHit = false;
textbox = "Test";
alarm[1] = 2*room_speed;
}
if (playerAccuracy > 10) {
playerCanHit = true;
}
//begin attack logic if CanHit is true
if (playerCanHit = true) {
//roll critical hit chance logic, if a 3 is rolled a second roll starts
criticalChance = irandom(3);
if (criticalChance = 3) {
critical5050 = irandom(2);
}
if (critical5050 = 1) {
damageModifier = 3;
}
if (critical5050 = 2) {
damageModifier = 2;
}
playerDamage = damageModifier * (playerBaseDamage + weaponDamage);
EnemyHealth = EnemyHealth - playerDamage;
draw_set_color(c_white);
draw_text(600, 400, enemyHealthDisplay);
}
//perform second roll for 50/50 chance of succeeding at critical
//perform calculation for and apply player attack damage
//begin enemy attack sequence
randomize();
EnemyAccuracy = irandom(60);
if (EnemyAccuracy > 10) {
EnemyCanHit = true;
}
if (EnemyAccuracy < 10) {
EnemyCanHit = false;
}
//begin attack logic if CanHit is true
if (EnemyCanHit = true) {
//roll critical hit chance logic, if a 3 is rolled a second roll starts
criticalChance = irandom(3);
//perform second roll for 50/50 chance of succeeding at critical
if (criticalChance = 3) {
critical5050 = irandom(2);
}
if (critical5050 = 1) {
damageModifier = 3;
}
if (critical5050 = 2) {
damageModifier = 2;
}
fightTimer = false;
enemyDamage = (damageModifier * EnemyBaseDamage);
playerHealth = playerHealth - enemyDamage;
draw_text(400, 400, playerHealthDisplay);
menu_control = true;
menu_committed = -1;
}
break;
//set fightTimer to false and apply enemy damage to player
case 0: game_end(); break;
}
}