===== 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:
* Where ''n'' is the number of the Olympic field, and ''html'' is the text or HTML code to display (e.g. ''olymp_value(3, 'Sanctuary')'').
[[https://qeng.org/game.php?jump_to&gid=3493&task_id=42715|Example of Olympic system]] | [[https://qeng.org/game.php?jump_to&gid=3493&task_id=49134|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.*
[[https://qeng.org/game.php?jump_to&gid=3493&task_id=52080|Example of answer hook in game]]
===== 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 ====
==== Composite Codes ====
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: [[en:authors_main:task_editor:advanced:composite_codes|Composite Codes]].
In short:
* **Nested templates** — the final code is assembled on the server and never reaches the page until every part is collected (**recommended**).
* **''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.
===== 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"**:
===== 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"**: