function game_hiddenpicture_continue($id, $game, $attempt, $hiddenpicture)
{
    global $CFG, $USER;
    if ($attempt != false and $hiddenpicture != false) {
        //Continue a previous attempt
        return game_hiddenpicture_play($id, $game, $attempt, $hiddenpicture);
    }
    if ($attempt == false) {
        //Start a new attempt
        $attempt = game_addattempt($game);
    }
    $cols = $game->param1;
    $rows = $game->param2;
    if ($cols == 0) {
        error(get_string('hiddenpicture_nocols', 'game'));
    }
    if ($rows == 0) {
        error(get_string('hiddenpicture_norows', 'game'));
    }
    //new attempt
    $n = $game->param1 * $game->param2;
    $recs = game_questions_selectrandom($game, $n);
    $newrec = game_hiddenpicture_selectglossaryentry($game, $attempt);
    if ($recs === false) {
        error(get_string('hiddenpicture_no_questions', 'game'));
    }
    $positions = array();
    $pos = 1;
    for ($col = 0; $col < $cols; $col++) {
        for ($row = 0; $row < $rows; $row++) {
            $positions[] = $pos++;
        }
    }
    $i = 0;
    foreach ($recs as $rec) {
        if ($i >= $n) {
            break;
        }
        unset($query);
        $query->attemptid = $newrec->id;
        $query->gamekind = $game->gamekind;
        $query->gameid = $game->id;
        $query->userid = $USER->id;
        $pos = array_rand($positions);
        $query->col = $positions[$pos];
        unset($positions[$pos]);
        $query->sourcemodule = $game->sourcemodule;
        $query->questionid = $rec->questionid;
        $query->glossaryentryid = $rec->glossaryentryid;
        $query->score = 0;
        if (($query->id = insert_record("game_queries", $query)) == 0) {
            error('error inserting in game_queries');
        }
    }
    //The score is zero
    game_updateattempts($game, $attempt, 0, 0);
    game_hiddenpicture_play($id, $game, $attempt, $newrec);
}
function game_hiddenpicture_continue($id, $game, $attempt, $hiddenpicture, $context)
{
    global $DB, $USER;
    if ($attempt != false and $hiddenpicture != false) {
        //Continue a previous attempt
        return game_hiddenpicture_play($id, $game, $attempt, $hiddenpicture, false, $context);
    }
    if ($attempt == false) {
        //Start a new attempt
        $attempt = game_addattempt($game);
    }
    $cols = $game->param1;
    $rows = $game->param2;
    if ($cols == 0) {
        print_error(get_string('hiddenpicture_nocols', 'game'));
    }
    if ($rows == 0) {
        print_error(get_string('hiddenpicture_norows', 'game'));
    }
    //new attempt
    $n = $game->param1 * $game->param2;
    $recs = game_questions_selectrandom($game, CONST_GAME_TRIES_REPETITION * $n);
    $selected_recs = game_select_from_repetitions($game, $recs, $n);
    $newrec = game_hiddenpicture_selectglossaryentry($game, $attempt);
    if ($recs === false) {
        print_error(get_string('no_questions', 'game'));
    }
    $positions = array();
    $pos = 1;
    for ($col = 0; $col < $cols; $col++) {
        for ($row = 0; $row < $rows; $row++) {
            $positions[] = $pos++;
        }
    }
    $i = 0;
    $field = $game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid';
    foreach ($recs as $rec) {
        if ($game->sourcemodule == 'glossary') {
            $key = $rec->glossaryentryid;
        } else {
            $key = $rec->questionid;
        }
        if (!array_key_exists($key, $selected_recs)) {
            continue;
        }
        $query = new stdClass();
        $query->attemptid = $newrec->id;
        $query->gamekind = $game->gamekind;
        $query->gameid = $game->id;
        $query->userid = $USER->id;
        $pos = array_rand($positions);
        $query->col = $positions[$pos];
        unset($positions[$pos]);
        $query->sourcemodule = $game->sourcemodule;
        $query->questionid = $rec->questionid;
        $query->glossaryentryid = $rec->glossaryentryid;
        $query->score = 0;
        if (($query->id = $DB->insert_record('game_queries', $query)) == 0) {
            print_error('error inserting in game_queries');
        }
        game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid);
    }
    //The score is zero
    game_updateattempts($game, $attempt, 0, 0);
    game_hiddenpicture_play($id, $game, $attempt, $newrec, false, $context);
}