Examples of using JavaScript in tasks. They should be inserted in the “Task Script” block (in the settings of a specific level).
$('#out_codes').hide();
$('#out_bonuses').hide();
$('#out_global_bonuses').hide();
$('#answer_result_right_out').text('Looks correct'); $('#answer_result_repeat_out').text('Already submitted'); $('#answer_result_wrong_out').text('Something is wrong');
show_time_on_task();
*Note: Only works if there is no auto-transition set for the level.*
$('span#out_end_time').each(function(){$(this).html($(this).html().replace('Автопереход', 'Time until zone closure'));});
$('span.hint_name').each(function(){$(this).html($(this).html().replace('Подсказка', 'Possible time until zone closure'));});
$('div#out_hints').each(function(){$(this).html($(this).html().replaceAll('Взять подсказку', 'Buy task'));});
[olymp] in the task text (it will be replaced with a table layout during the game).olymp('8.2');olymp_with_numbers('8.2');<script>olymp_value(n, 'html')</script>
n is the number of the Olympic field, and html is the text or HTML code to display (e.g. olymp_value(3, 'Sanctuary')).Example of Olympic system | Example with tasks in starting cells
Insert into the task text:
Total points: !bonus!
You can intercept and modify submitted answers in the browser before they are sent to the server (e.g., automatically prepend a prefix p_):
window.submitAnswerCallback = function(answer) { return 'p_' + answer; }
*If the function returns an empty string, the answer will not be sent to the server.*
These scripts must be inserted in the solution text field of bonuses/hints in “Source” mode:
<script>enter('Code to submit')</script>
If the final code consists of parts scattered across different codes, bonuses, global bonuses and hints, there are three ways to assemble and submit it automatically — they are described on a dedicated page: Composite Codes.
In short:
getAllParts() / getAllBonuses() — concatenating answers already shown on the page, from the task script.code_part() — a legacy option, kept for compatibility with older games.Important: whichever method you use, make sure to add the final assembled code to the level as a standard main code, otherwise the page will reload in a loop trying to submit a non-existent code.
If you need to call a script on every task refresh in the game, write it in the “Common HTML header of the game”:
<script> document.addEventListener("DOMContentLoaded", function() { function common_task_script() { console.log('level refreshed'); } let old_task_script = task_script; task_script = function() { old_task_script(); common_task_script(); }; common_task_script(); }); </script>
To automatically redirect a team to the main game dashboard if they open an already completed storm task, insert into the “Common HTML header of the game”:
<script>
document.addEventListener("DOMContentLoaded", function() {
if ($('.closed-level').length > 0) {
window.location = 'game.php?gid=' + game_id;
}
});
</script>