Posted By: Reconnoiter
hold key code returns very high value instead of 0 or 1 - 12/16/17 14:20
Hi,
Below is some code I wrote to check if the player holds a key for a 0.5 sec (instead of a normal/quick key press or left mouse button or such), and if so let the player do some other action. However the function returns some weird high value (whether holding the key or not) and doesn't beep, but I am not entirely sure why, maybe something with waiting before returning the value?:
Below is some code I wrote to check if the player holds a key for a 0.5 sec (instead of a normal/quick key press or left mouse button or such), and if so let the player do some other action. However the function returns some weird high value (whether holding the key or not) and doesn't beep, but I am not entirely sure why, maybe something with waiting before returning the value?:
Code:
#define KEYTYPE_HOLD 1 //Returns whether key is hold or not function get_keyType() { var _keyType = 0; var _holdDur = 0.5; //sec var _timer = 0; //sec while (_timer < _holdDur) { //mouse_left && _timer += time_step/16; wait(1); } if (_timer >= _holdDur) _keyType = KEYTYPE_HOLD; return _keyType; } .... .... void ... () { var _keyType = -1; _keyType = get_keyType(); while(_keyType == -1) wait(1); //wait for return value debug_var1 = _keyType; //used as DEBUG_VAR(debug_var1, 430); if (_keyType == KEYTYPE_HOLD) { beep(); .... } }