As is, this loop works fine. Although I feel like its inefficient because it doesnt need to keep updating the nonce counter each time it loops, that only needs to be done once.
So when I try and move the UPDATE NONCE COUNTER code out of the loop or to a different part of the loop, it breaks the form processing with the error: Warning: array_filter() expects parameter 1 to be array, integer given in /wp-includes/post.php on line 3371
Original Loops:
/*********************/
/* PLAYING THE GAME. */
/*********************/
for ($a = 0; $a <= 1000; $a++) {
/* UPDATE NONCE COUNTER */
$current_nonce = get_user_meta($player_id, 'nonce_counter', true);
$new_nonce = $current_nonce + 1;
$update_nonce = update_user_meta( $player_id, 'nonce_counter', $new_nonce);
$game_string = $player_string . "-" . $current_nonce;
/* GAME HASH. */
$game_hash = hash_hmac('tiger128,4', $game_string, $server_key);
/* GENERATE THE STARTING TOKEN COUNT */
/* take the $game_hash and get the first 27 chars and convert that to a number to */
/* be used as the starting point for the game. The starting number must be larger than 99,999. */
/* the starting number is then reduced to a smaller number to be used for actual game play. */
$game_hash_string = substr($game_hash,0,27);
$game_hash_value = intval($game_hash_string);
if ($game_hash_value > 99999) {
$game_start_value = $game_hash_value;
for($i = $game_start_value; $i >= 1; $i-=4) {
$winning_number = $i;
}
break;
}
}
I feel like a better version of this should be something like this:
/*********************/
/* PLAYING THE GAME. */
/*********************/
for ($a = 0; $a <= 1000; $a++) {
/* GENERATE THE STARTING TOKEN COUNT */
/* take the $game_hash and get the first 27 chars and convert that to a number to */
/* be used as the starting point for the game. The starting number must be larger than 99,999. */
/* the starting number is then reduced to a smaller number to be used for actual game play. */
$game_hash_string = substr($game_hash,0,27);
$game_hash_value = intval($game_hash_string);
if ($game_hash_value > 99999) {
/* UPDATE NONCE COUNTER */
$current_nonce = get_user_meta($player_id, 'nonce_counter', true);
$new_nonce = $current_nonce + 1;
$update_nonce = update_user_meta( $player_id, 'nonce_counter', $new_nonce);
// GAME STRING //
$game_string = $player_string . "-" . $current_nonce;
/* GAME HASH. */
$game_hash = hash_hmac('tiger128,4', $game_string, $server_key);
$game_start_value = $game_hash_value;
for($i = $game_start_value; $i >= 1; $i-=4) {
$winning_number = $i;
}
}
}
where it only update the nonce after the starting number has been determined. but when i try to do this, i get the error: Warning: array_filter() expects parameter 1 to be array, integer given in /wp-includes/post.php on line 3371