I
inkBot
Guest
I'm working on getting the game to recognize a string of inputs in order to do special moves, fighting game style.
For every input I add to the variable "det_input" which I will later check if there's a viable string there and then execute a script relating to what string it is.
The trouble I'm having is that my code will add extra characters. I know what is causing it. It's the parts I added that would check if the player presses one direction while another direction is held. This is to detect diagonals.
So if the player presses down, down+right, right, then the string in det_input would be "236", but it's not. Instead it becomes 2366. It will add 2 first, then 3 and 6 at the same time, and last 6 again.
Here's my mad mess of a code for this:
As I said, I have a fairly good idea of what is causing the issue, but I'm unclear about how to fix it.
(Edit: There are probably plenty things that I could be doing better with the structure of it all)
For every input I add to the variable "det_input" which I will later check if there's a viable string there and then execute a script relating to what string it is.
The trouble I'm having is that my code will add extra characters. I know what is causing it. It's the parts I added that would check if the player presses one direction while another direction is held. This is to detect diagonals.
So if the player presses down, down+right, right, then the string in det_input would be "236", but it's not. Instead it becomes 2366. It will add 2 first, then 3 and 6 at the same time, and last 6 again.
Here's my mad mess of a code for this:
Code:
// Detects the input from keyboard and returns a string
// Attack Buttons
if keyboard_check_pressed(ord("D")) det_input = det_input + "A"; // Light Attack
if keyboard_check_pressed(ord("F")) det_input = det_input + "B"; // Medium Attack
if keyboard_check_pressed(ord("G")) det_input = det_input + "C"; // Heavy Attack
if keyboard_check_pressed(vk_space) det_input = det_input + "D"; // Jump
if keyboard_check_pressed(ord("B")) det_input = det_input + "E"; // Guard
if keyboard_check_pressed(ord("H")) det_input = det_input + "F"; // Pick Up Item/Misc Action
// Detects when releasing one of two held directions
if keyboard_check(vk_right) && keyboard_check_released(vk_down) det_input = det_input + "6";
if keyboard_check(vk_down) && keyboard_check_released(vk_right) det_input = det_input + "2";
if keyboard_check(vk_right) && keyboard_check_released(vk_up) det_input = det_input + "6";
if keyboard_check(vk_up) && keyboard_check_released(vk_right) det_input = det_input + "8";
if keyboard_check(vk_left) && keyboard_check_released(vk_down) det_input = det_input + "4";
if keyboard_check(vk_down) && keyboard_check_released(vk_left) det_input = det_input + "2";
if keyboard_check(vk_left) && keyboard_check_released(vk_up) det_input = det_input + "4";
if keyboard_check(vk_up) && keyboard_check_released(vk_left) det_input = det_input + "8";
// Directionals
if keyboard_check_pressed(vk_right)
{
if keyboard_check(vk_down)
{
det_input = det_input + "3";
}
if keyboard_check(vk_up)
{
det_input = det_input + "9";
}
else
{
det_input = det_input + "6";
}
}
if keyboard_check_pressed(vk_left)
{
if keyboard_check(vk_down)
{
det_input = det_input + "1";
}
if keyboard_check(vk_up)
{
det_input = det_input + "7";
}
else
{
det_input = det_input + "4";
}
}
if keyboard_check_pressed(vk_down)
{
if keyboard_check(vk_right)
{
det_input = det_input + "3";
}
if keyboard_check(vk_left)
{
det_input = det_input + "1";
}
else
{
det_input = det_input + "2";
}
}
if keyboard_check_pressed(vk_up)
{
if keyboard_check(vk_right)
{
det_input = det_input + "9";
}
if keyboard_check(vk_left)
{
det_input = det_input + "7";
}
else
{
det_input = det_input + "8";
}
}
(Edit: There are probably plenty things that I could be doing better with the structure of it all)