Computer Science Canada

Detecting when an array char of boolean is empty

Author:  BetterthanNothin [ Wed May 29, 2019 12:47 am ]
Post subject:  Detecting when an array char of boolean is empty

This may sound super dumb but if you have an array char of boolean, how would you detect it's empty? Like no keys are pressed?

Author:  Insectoid [ Fri May 31, 2019 9:17 pm ]
Post subject:  RE:Detecting when an array char of boolean is empty

You'll need a for loop that iterates over every char and checks each for a keypress. You'll need the char() command (if I remember right) to convert your for loop iterator into chars you can pass to the array. Something like this:

Function keyPressed : boolean
For c : 1..120 % experiment to find the right values here, 120 is made up
If char_array(char(c)) then return true % if this ever returns true, a key was pressed
end for
Return false % this will only run if no keys were pressed
End keyPressed

You can also use the hasch() function, which pretty much does what you want, without bothering with char arrays or Input.Keydown.


: