====== Salet core ====== The ''Salet'' class; the only instance of this class is automatically available as ''window.salet''. ===== CoffeeScript properties ===== ==== character ==== An instance of ''[[en:api:character|Character]]'' class, the game's playable character. Every property in this class that can be serialized (i.e. not functions) gets in the save. ==== game_id ==== **Globally Unique** ID of the game, arbitrary string. Manages the save slot. You **must** redefine this property in your game, or you'll be sharing the save slot with other games (and that will break all of these games). Use [[https://en.wikipedia.org/wiki/Universally_unique_identifier|UUIDs]] to avoid collisions. ==== game_version ==== Game version, arbitrary string. It corresponds to the save slot too (each new version gets a new slot). ==== autosave ==== Automatic save flag. If ''true'', then Salet would save the game when entering every room that has ''[[en:api:room#canSave|canSave]] = true''. ''true'' by default. ==== autoload ==== Automatic load flag. If ''true'', then Salet would automatically load the saved game on page load. If you set this to ''false'' it's implied you have your own interface to load the game, also see ''[[#loadGame]]''. It's useful for all sorts of intro menus, where you don't want to continue right where the player left the game. ==== rnd ==== An instance of the ''[[en:api:random|Random]]'' class. ==== time ==== Time in seconds spent since start of the game. A floating point number. ==== startTime ==== A date in seconds when the game started. A floating point number, read as Unix time. ==== linkRe ==== A regular expression that controls which links are considered internal. By default, a link is internal when it consists only of Latin letters, digits, dash and underscore signs: ''room'' or ''room.action'' or ''./action''. ==== current ==== ID of the current room, where the player is right now. ==== interactive ==== The flag that shows if Salet is in the interactive mode. If it's ''true'', the game is going on right now; if ''false'', the game is loading (non-interactive mode). In non-interactive mode, all visual animations are skipped. ==== linkStack ==== A system object; a stack of links that are not parsed yet. ==== progress ==== A system object; all data to save. Contains the RNG seed ''seed'', a sequence of visited links ''sequence'', a sequence of visited rooms ''path'' and save time ''saveTime''. ==== view ==== A system object; instance of the ''[[en:api:view|SaletView]]'' class. ==== start ==== ID of the room the player starts in, ''start'' by default ==== rooms ==== A system object; keeps all the game rooms. ==== timers ==== A system property for all the game timers. ===== CoffeeScript methods ===== ==== init ==== The function called at the start of the game. It's convenient to redefine in your game to initialize the game state. (You also can do that in the on-entering callback ''enter'' of the starting room) ==== enter ==== The function called when the player enters any room. It's called before the ''enter'' handler of the new room. **Argument 1:** old room's ID **Argument 2:** new room's ID ==== afterEnter ==== The function called when the player enters any room. It's called after the ''enter'' handler of the new room. **Argument 1:** old room's ID **Argument 2:** new room's ID ==== beforeAction ==== The function called before any action in any room. If it returns ''true'' then the action is considered consumed and the room's handler won't act. **Argument 1:** room's ID **Argument 2:** action ID ==== afterAction ==== The function called after any action in any room. **Argument 1:** room's ID **Argument 2:** action ID ==== exit ==== The function called when the player exits any room before the ''exit'' handler of the old room is called. **Argument 1:** old room's ID **Argument 2:** new room's ID ==== getSituationIdChoices ==== Системная функция, которая собирает список комнат по указанному тегу и фильтрует его по размеру. Вызывается при создании автосписков неявного выбора. **Argument 1:** тег для фильтра **Argument 2:** максимальная длина списка на выходе ==== getCurrentRoom ==== Returns a room (''SaletRoom'') where the player is. Aliases: ''[[#here]]'' ==== getSaveId ==== Returns ID of the save. ==== processLink ==== A system function; link handler. **Argument 1:** link target ==== goTo ==== Moved the player to another room. An alias for ''[[#processClick]]''. **Argument:** room ID ==== processOneLink ==== A system function; processes one link. **Argument 1:** link target ==== processClick ==== A system function; processes one link. **Argument 1:** link target ==== goBack ==== Returns the player to ''N'' rooms back. It's not an UNDO command, but rather a "go where I've been" command. ''N = 1'' is the current room. **Argument:** number of rooms to go back, ''2'' by default ==== doTransitionTo ==== A system function; movement between rooms. **Argument 1:** new room ID **Argument 2:** forced movement flag (passed to the handlers), ''false'' by default ==== eraseSave ==== Shows a warning "do you really want to erase the save?" If the player agrees, erases the save and restarts the game. **Argument:** forced erase flag (skips the warning), ''false'' by default. ==== getRoomsTagged ==== Returns an array of rooms having the specified tag. **Argument:** tag to search. ==== saveGame ==== Saves the game. ==== loadGame ==== Loads the game from the save data. **Argument:** save data ==== getSave ==== Function that returns the save data. ==== beginGame ==== A system function that initializes Salet and begins the game. Calls the ''[[#init]]'' function, loads the game if the save is found and ''[[#autoload]]'' is on. ==== here ==== An alias for ''[[#getCurrentRoom]]'' ==== isVisited ==== Returns ''true'' if the player visited the specified room at least once. **Argument:** room ID ==== addTimer ==== This function adds a timer in the game. Timer is a text or a function that will be called after several steps. Step is every click (in-game action). A timer can be repeatable (called every ''step'' number of steps) or one-time (is removed after the first call). **Argument 1:** timer name, mandatory **Argument 2:** timer action, mandatory. Can be a string or a function. The value returned by the function is appended to the game text. **Argument 3:** repeatable flag, ''false'' by default. **Аргумент 4:** number of steps, ''1'' by default. ==== dropTimer ==== The function drops the specified timer. This action cannot be undone. **Argument:** timer name ==== resetTimer ==== Resets the specified timer. **Argument:** timer name ==== checkTimer ==== A system function that checks and calls all game timers. Called after every click in the game. {{tag>api}}