Typical Scripts
Examples of using JavaScript in tasks. They should be inserted in the “Task Script” block (in the settings of a specific level).
Hide Codes
$('#out_codes').hide();
Hide Bonuses
$('#out_bonuses').hide();
Hide Global (Spanning) Bonuses
$('#out_global_bonuses').hide();
Show Custom Messages Instead of Original Code Submission Results
$('#answer_result_right_out').text('Looks correct'); $('#answer_result_repeat_out').text('Already submitted'); $('#answer_result_wrong_out').text('Something is wrong');
Display Time Spent on Task Instead of Auto-transition Timer
show_time_on_task();
*Note: Only works if there is no auto-transition set for the level.*
Replace 'Auto-transition' with Another Name
$('span#out_end_time').each(function(){$(this).html($(this).html().replace('Автопереход', 'Time until zone closure'));});
Replace 'Hint' with Another Name
$('span.hint_name').each(function(){$(this).html($(this).html().replace('Подсказка', 'Possible time until zone closure'));});
Replace Text on 'Get Hint' Button
$('div#out_hints').each(function(){$(this).html($(this).html().replaceAll('Взять подсказку', 'Buy task'));});
Olympic Tournament (Playoff Grid)
- Write
[olymp]in the task text (it will be replaced with a table layout during the game). - Write in the task script:
olymp('8.2');- Instead of `'8.2'`, you can use `'4.2'`, `'16.2'`, `'32.2'`, `'64.2'`, `'128.2'`, `'256.2'`, `'9.3'`, `'27.3'`, `'81.3'`, `'16.4'`, `'64.4'` (where the first number is the number of starting codes, and the second is the cell merging count in subsequent stages).
- If you want to keep the numbers in the codes, use:
olymp_with_numbers('8.2');
- To display a custom value instead of the submitted word in the bracket:
- Create a bonus with the same code.
- In the “Text after solution” field of that bonus, in Source mode, insert:
<script>olymp_value(n, 'html')</script>
- Where
nis the number of the Olympic field, andhtmlis the text or HTML code to display (e.g.olymp_value(3, 'Sanctuary')).
Example of Olympic system | Example with tasks in starting cells
Displaying Earned Storm Points in Task Description
Insert into the task text:
Total points: !bonus!
Task Answer Handler
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.*
Scripts in Bonuses and Hints
These scripts must be inserted in the solution text field of bonuses/hints in “Source” mode:
Automatically Submit Code on Hint/Bonus Reveal
<script>enter('Code to submit')</script>
Composite Codes in Bonuses / Penalty Hints
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, use0).'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>
System Events: Invoking a Script on Task Refresh
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>
Auto-redirect in Storm Games (Do not show closed tasks)
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>