Hello! I am writing a developer console for my game and I need to check for a string/regex pattern before a message is logged/pushed to the console, but I cannot seem to figure out the solution.
consoleRegex = "abcdefghijklmnopqrstuvwxyz-_+=<>.,/\|{}[]12345678910 ";
static PushMessage = function( msg, ignore_history = false ) {
/*
BUG:
Filtered messages do not get pushed.
*/
var _message = string_lower( msg );
var _regex = string_split( consoleRegex, "" );
var _filtered_msg = string( "" );
for( var i = 1; i <= array_length( _message ); ++i ) {
var _char = string_char_at( _message, i );
if ( string_pos( _char, _regex ) > 0 ) {
_filtered_msg += _char;
}
}
if ( string_length( _message ) > 0 ) {
if ( array_length( consoleLog ) < consoleMaxLog ) {
array_push( consoleLog, _message );
if ( !ignore_history ) {
array_push( consoleHistory, _message );
}
}
else {
// Shift the array if the log and history are full.
array_shift( consoleLog );
array_push( consoleLog, _message );
if ( !ignore_history ) {
array_shift( consoleHistory );
array_push( consoleHistory, _message );
}
}
}
}