FANDOM


    The *script command allows for JavaScript to be used directly in a ChoiceScript game.

As ChoiceScript works on top of JavaScript there should be no errors if it is used correctly, however, the *script command and other JavaScript elements are beyond the scope of this wiki and ChoiceScript in general, and is not supported by Choice of Games, the ChoiceScript Development team, nor the ChoiceScript community. Additionally, as the *script command requires prior knowledge of JavaScript, unless you are already proficent in JavaScript, the *script command should be avoided.

Usage

A basic use of *script is as follows:

*temp terminale
*set terminale false
*label menu
[b]CSS Demo[/b]
*choice
 *if (terminale = false) #Change to Computer Terminal CSS
   *set terminale true
   *script changeDisplay("terminal")
   *goto menu
 *if (terminale) #Change to Story CSS
   *set terminale false
   *script changeDisplay("story")
   *goto menu

Then, in a javascript file (it is recommended that you declared another file in index.html and use that instead of one of the preexisting files to make updating and error checking easier):

function changeDisplay(type) {
var body = document.getElementById("body");
if (type == "terminal") { 
body.style.fontFamily = "Courier New", "Lucida Console", "Arial";
body.style.backgroundColor = "#000000";
body.style.color = "#5DFC0A";
  }

if (type == "story") {
body.style.fontFamily = "Georgia","Times New Roman", "serif";
body.style.backgroundColor = "#F7F4F1";
body.style.color = "rgba(0, 0, 0, 0.85)";
 }
}

This will make a choice which switches the style of the page between what is normally is, and an old fashioned computer terminal, with a black background and green text.

In short, with *script, anything that JavaScript can do, ChoiceScript can also do, so long as you already know JavaScript.


More commands
Choice *choice, *fake_choice, *disable_reuse, *hide_reuse, *allow_reuse, *selectable_if
Variable *create, *temp, *set, Arithmetic operators, *delete, *input_number, *input_text, *print, *rand
Conditional *if, *elseif, *else
Goto *label, *goto, *goto_scene, *goto_random_scene, *gosub, *gosub_scene, *finish
Formatting Bold text, Italic text, *image, *line_break, *page_break, *link, *stat_chart
Miscellaneous *comment, *scene_list, *title, *author, *achieve, *achievement, *check_achievements, *bug, *ending, *more_games, *share_this_game, *show_password, *script

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.