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 a code consists of multiple parts scattered across different hints or bonuses:
<script>code_part(composite_code_number, 'code_part_string', total_composite_parts)</script>
composite_code_number — index number of the composite code if there are multiple (if it's the only one, use 0).'code_part_string' — the string fragment (must be quoted).
* total_composite_parts'' — the total number of parts to collect.<note important> Important: 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. </note>
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>