### Full Example Using KAG Script Command Lines Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Letter.html Rewrites the previous example demonstrating click waits, line breaks, and page breaks, using the command line syntax (@) for tags like wait and cm. ```KAG Script @wait time=200 *start|スタート @cm こんにちは。[l][r] ごきげんよろしゅう。[l][r] 改ページしますよ。[p] @cm 改ページしました。 ``` -------------------------------- ### Get User Input and Convert to Number (input, str2num) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Prompts the user to input a value into the variable `f.kazu` using the `input` tag, then immediately converts the value in `f.kazu` from a string to a number using the `str2num` function. ```KAG/TJS [input name="f.kazu" prompt="数値を入力してください"][emb exp="f.kazu=str2num(f.kazu)"] ``` -------------------------------- ### Example: Alt+Enter Shortcut (TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_MenuItem_shortcut.html This example illustrates the string format for a shortcut using the Alt modifier key and the Enter key. ```String "Alt+Enter" ``` -------------------------------- ### Example: Shift+Alt+E Shortcut (TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_MenuItem_shortcut.html An example showing how to combine multiple modifier keys (Shift and Alt) with a target key ('E') in the shortcut string format. ```String "Shift+Alt+E" ``` -------------------------------- ### KAG Script Command Line Syntax Example Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Letter.html Shows the equivalent command line syntax for the [wc time=20] tag, using the @ prefix instead of square brackets. ```KAG Script @wc time=20 ``` -------------------------------- ### Register Key Down Hook - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Registers a TJS function `myKeyDownHook` to the `kag.keyDownHook` array. The function receives the key code and shift state. The example checks for the 'R' key, jumps to a label, and removes the hook if 'R' is pressed. Returning `true` prevents KAG's default key behavior. ```KAG/TJS @iscript function myKeyDownHook(key, shift) { if(key == #'R') { // R のキーが押されたら kag.process('', '*label'); return true; } } @endscript @eval exp="kag.keyDownHook.add(myKeyDownHook)" @s *label @eval exp="kag.keyDownHook.remove(myKeyDownHook)" やあー。 @s ``` -------------------------------- ### Register Left Click Hook - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Registers a TJS function `myLeftClickHook` to the `kag.leftClickHook` array. The function is called on left click (or Enter/Space). Returning `true` prevents KAG's default click behavior. The example jumps to a label and then removes the hook. ```KAG/TJS @iscript function myLeftClickHook() { kag.process('', '*label'); return true; } @endscript @eval exp="kag.leftClickHook.add(myLeftClickHook)" @s *label @eval exp="kag.leftClickHook.remove(myLeftClickHook)" やあー。 @s ``` -------------------------------- ### KAG Script Tag Syntax Example Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Letter.html Shows the basic syntax for a KAG tag, including the tag name (wc) and an attribute (time=20). ```KAG Script [wc time=20] ``` -------------------------------- ### Get Current Date and Time - TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Retrieves the current date and time using the TJS `Date` object and stores its components (year, month, day, hour, minute, second) into `f` variables. Variables declared within the `{}` block are local. ```TJS [iscript] { // ↑ endscript の中を { } で囲むのは この中で宣言された変数を // ローカル変数にするため ( そうしないとグローバル変数になる ) var d = new Date(); // Date クラスのオブジェクトを作成 // Date クラスのオブジェクトは、作成時に引数に何も指定しなければ // 作成時点の現在時刻を保持している f.year = d.getYear(); // f.year に 年 f.month = d.getMonth() + 1; // f.month に 月 f.date = d.getDate(); // f.date に 日 f.hours = d.getHours(); // f.hours に 時 f.minutes = d.getMinutes(); // f.minutes に 分 f.seconds = d.getSeconds(); // f.seconds に 秒 } [endscript] ``` -------------------------------- ### Read Registry Value (System.readRegValue) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Reads the string or numerical value from the Windows registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Dee\kirikiri\installpath' and assigns it to the variable `f.installpath`. Note the escaping of backslashes in the key path. ```KAG/TJS [eval exp="f.installpath = System.readRegValue('HKEY_LOCAL_MACHINE\\SOFTWARE\\Dee\\kirikiri\\installpath')"] ``` -------------------------------- ### Example: Shift+Esc Shortcut (TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_MenuItem_shortcut.html This snippet shows an example of a valid string format for the MenuItem.shortcut property, combining the Shift modifier key with the Escape key. ```String "Shift+Esc" ``` -------------------------------- ### TJS2 Whitespace Usage Examples Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/style.html TJS2 is a free-style language like C, allowing flexible use of whitespace (spaces, tabs, newlines) between tokens where it does not alter meaning. Examples (1) through (4) demonstrate valid variations of function definition with different whitespace arrangements; (2) or (3) are recommended for readability. Example (5) is invalid because necessary spaces between tokens are missing. Example (6) is invalid due to misplaced spaces within tokens. ```TJS2 function func(a,b) { a++; return a+b; } ``` ```TJS2 function func(a,b) { a++; return a+b; } ``` ```TJS2 function func(a,b) { a++; return a+b; } ``` ```TJS2 function func ( a , b ) { a ++ ; return a + b ; } ``` ```TJS2 functionfunc(a,b){a++;returna+b;} ``` ```TJS2 f unction fu nc(a,b) { a+ +; ret urn a+b; } ``` -------------------------------- ### Control Scenario Flow with kag.process - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Uses the `kag.process` method to jump to a specified label within the current scenario file (empty string for the first argument) or a different scenario file. This forces a change in execution flow. ```KAG/TJS kag.process('', '*label2') kag.process('scenario4.ks', '*label5') ``` -------------------------------- ### Pre-load Images with System.touchImages - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Uses the `System.touchImages` method to load specified images into the cache during a wait period. This helps improve performance by having images ready before they are displayed. The second and third arguments control cache size hint and wait time. ```KAG/TJS @resetwait @eval exp="System.touchImages(['24_5', '24_4', 'uni', '24'], -2*1024*1024, 800)" @wait mode=until time=1000 ``` -------------------------------- ### TJS2 Naked Word Examples Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples illustrating the rules for valid and invalid 'naked words' (identifiers and reserved words) in TJS2, which must start with a letter or underscore and can contain letters, underscores, digits, or full-width characters. ```TJS2 ampan // OK 123a // 数字が先頭に来ているので NG _asdf // アンダーバーは先頭にくることができるので OK continue // これは予約語 OK 全角文字 // いわゆる全角文字は「裸の単語」として OK ``` -------------------------------- ### Example: Ctrl+F1 Shortcut (TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_MenuItem_shortcut.html Demonstrates the string format for combining the Ctrl modifier key with a function key (F1) as a shortcut. ```String "Ctrl+F1" ``` -------------------------------- ### Example: Ctrl+S Shortcut (TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_MenuItem_shortcut.html This snippet demonstrates the string format for specifying a shortcut using the Ctrl modifier key and the 'S' key. ```String "Ctrl+S" ``` -------------------------------- ### Example: Single Key Shortcut (TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_MenuItem_shortcut.html Shows that a shortcut can be specified using just a single key name without any modifier keys. ```String "T" ``` -------------------------------- ### Add Folder to Auto Search Path (Storages.addAutoPath) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Adds the 'cgdata' folder located in the same directory as the Kirikiri executable (`System.exePath`) to the list of automatic search paths for files. The trailing '/' indicates a folder. ```KAG/TJS [eval exp="Storages.addAutoPath(System.exePath + 'cgdata/')"] ``` -------------------------------- ### Create 2D Array (Initialization Loop) - TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Creates a 2D array by initializing the first dimension and then iterating to initialize each element of the first dimension as an empty array, ensuring they are created only if currently `void`. This method fixes the size of the first dimension. ```TJS @iscript // 1次元目の要素数が 5 の2次元配列を作成する f.twodim = [] if f.twodim === void; // twodim に1次元目の配列を作成 for(var i = 0; i < 5; i++) f.twodim[i] = [] if f.twodim[i] === void; // この状態で f.twodim[0] ~ f.twodim[4] がそれぞれ配列なので // f.twodim[0][3] や f.twodim[4][2] などと指定できる @endscript ``` -------------------------------- ### Display Array Elements - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Displays the values of array elements using the `emb` tag and index notation. This allows embedding the value directly into the text output. ```KAG/TJS 0 : [emb exp="f.hairetsu[0]"] 1 : [emb exp="f.hairetsu[1]"] ``` -------------------------------- ### Add CD Folder to Auto Search Path (Storages.addAutoPath, Storages.searchCD) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Finds the drive letter of a CD-ROM with the volume label 'FOO_BAR_DISC' using `Storages.searchCD`, and then adds the 'image' folder on that CD-ROM to the automatic search paths. ```KAG/TJS [eval exp="Storages.addAutoPath(Storages.searchCD('FOO_BAR_DISC') + ':image/')"] ``` -------------------------------- ### TJS2 String Escape Sequence Examples Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples demonstrating the use of escape sequences like \' and \xH within TJS2 strings. Explains how \xH interprets subsequent hexadecimal digits as a character code. ```TJS2 'Can\'t help' ( \' を用いている ) "\x1234" ( ワイド文字としての 0x1234 という文字コードの文字 ) ``` -------------------------------- ### Add Archive to Auto Search Path (Storages.addAutoPath) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Adds the 'cgdata.xp3' archive file located in the same directory as the Kirikiri executable (`System.exePath`) to the list of automatic search paths for files. The trailing '>' indicates an archive. ```KAG/TJS [eval exp="Storages.addAutoPath(System.exePath + 'cgdata.xp3>')"] ``` -------------------------------- ### Check if Registry Value Exists (System.readRegValue, void) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Checks if the variable `f.installpath`, previously populated by `System.readRegValue`, is `void`. This indicates that the specified registry value did not exist. If it is `void`, a message is displayed. ```KAG/TJS [if exp="f.installpath === void"]インストールされていません[endif] ``` -------------------------------- ### Format Number with Commas (number_format) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Displays the value of the variable `f.num` formatted with commas as a thousands separator using the `number_format` function. ```KAG/TJS @emb exp="number_format(f.num)" ``` -------------------------------- ### Display Dictionary Elements - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Displays the values of dictionary elements using the `emb` tag and string keys within square brackets `[]`. Dot notation (`.`) can also be used for keys that are valid identifiers. ```KAG/TJS zero : [emb exp="f.dict['zero']"] one : [emb exp="f.dict['one']"] ``` -------------------------------- ### Test String Against Regex (test) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Uses a regular expression `/[^0-9]/` to test if the variable `f.nyuryoku` contains any non-digit characters. If it does, it displays a message. ```KAG/TJS [if exp="/[^0-9]/.test(f.nyuryoku)"]入力された文字に数字以外が混じっています[endif] ``` -------------------------------- ### Assign Values to Dictionary Elements - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Assigns values to elements of a dictionary array using string keys within square brackets `[]`. Multiple assignments can be chained with a comma. ```KAG/TJS [eval exp="f.dict['zero'] = 0, f.dict['one'] = 1"] ``` -------------------------------- ### TJS2 Decimal Numeric Literals Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples of standard decimal integer and floating-point numeric literals as recognized by TJS2. ```TJS2 0 3.1 342.3 1 ``` -------------------------------- ### TJS2 Numeric Literals with Exponents Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples demonstrating the use of 'e' or 'E' for specifying base-10 exponents in TJS2 numeric literals. ```TJS2 1e-3 // 1×10-3 3.4e10 // 3.4×1010 9.3E-2 // 9.3×10-2 ``` -------------------------------- ### Match String Against Regex and Extract Groups (match) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Uses a regular expression to match the format 'number-number' (including full-width digits) in `f.input`. If matched, it extracts the two number parts into `f.matched[1]` and `f.matched[2]`, converts them to numbers using `str2num`, and assigns them to `f.s1` and `f.s2`. If not matched, it displays an error and jumps. ```KAG/TJS [eval exp="f.matched = /([0-90-9]+)[--]([0-90-9]+)/.match(f.input)"] [if exp="f.matched.count == 0"]「数値-数値」の形式で入力してください。[jump target=*input][endif] [eval exp="f.s1 = str2num(f.matched[1]), f.s2 = str2num(f.matched[2])"] ``` -------------------------------- ### Handling Exceptions with Basic Try-Catch in TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/try.html This example demonstrates the fundamental use of `try` and `catch` blocks to handle potential exceptions. Code that might fail is placed in the `try` block, and if an exception occurs, the `catch` block is executed. ```TJS try // 例外が発生するするかもしれないので { func1(); // ここでは例外が発生するかもしれない } catch // 例外を捕捉する { // 例外がおきたとき、ここが実行される inform("画像を読み込むことができません。"); // メッセージを表示する } ``` -------------------------------- ### TJS2 Binary Numeric Literals Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples of binary numeric literals in TJS2, which are prefixed with '0b' or '0B'. ```TJS2 0b0100 0B0010100010100001 ``` -------------------------------- ### Check if CD with Volume Label is Inserted (Storages.searchCD) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Checks if a CD-ROM with the volume label 'FOO_BAR_DISC' is currently inserted in a drive by calling `Storages.searchCD`. If the function returns an empty string, the CD was not found, and a message is displayed. ```KAG/TJS [if exp="Storages.searchCD('FOO_BAR_DISC') == ''"]CDが挿入されていません[endif] ``` -------------------------------- ### TJS2 Octal Numeric Literals Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples of octal numeric literals in TJS2, which are prefixed with '0'. ```TJS2 01234 033 ``` -------------------------------- ### Initialize Array if Void - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Initializes a variable as an empty array only if its current value is `void`. This is useful for system variables that might retain values across game sessions. ```KAG/TJS [eval exp="sf.hairetsu = [] if sf.hairetsu === void"] ``` -------------------------------- ### Create 2D Array (Literal Notation) - TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Creates a 2D array using array literal notation, initializing the first dimension with a fixed number of empty arrays. This is a simpler way to create a 2D array with a predetermined size for the first dimension. ```TJS f.twodim = [ [], [], [], [], [] ]; ``` -------------------------------- ### Assign Values to Array Elements - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Assigns values to specific elements of an array using zero-based index notation within an `eval` tag. Multiple assignments can be chained with a comma. ```KAG/TJS [eval exp="f.hairetsu[0] = 'zero', f.hairetsu[1] = 'one'"] ``` -------------------------------- ### Convert Number to Japanese Kanji Numerals (kansuuji) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Displays the value of the variable `f.num` converted into traditional Japanese Kanji numerals using the `kansuuji` function. ```KAG/TJS @emb exp="kansuuji(f.num)" ``` -------------------------------- ### Declare Dictionary Array - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Declares a variable as a dictionary array (associative array) using the `%[]` notation within an `eval` tag. Similar to standard arrays, existing content will be cleared. ```KAG/TJS [eval exp="f.dict = %[]"] ``` -------------------------------- ### TJS2 Octet Literals Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples of octet literals in TJS2, enclosed in '<% %>' and containing binary data represented by space-separated two-digit hexadecimal numbers. ```TJS2 <% 00 01 02 03 %> <% ff ff ff 00 04 0f ff 30 %> ``` -------------------------------- ### Check String Contains Substring (indexOf) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Checks if the variable `f.itemname` contains the substring 'コップ'. Executes the block if the substring is found. ```KAG/TJS [if exp="f.itemname.indexOf('コップ')!=-1"]~~[endif] ``` -------------------------------- ### TJS2 Regular Expression Patterns Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples of regular expression patterns in TJS2, enclosed in '/' characters. Optional flags (g, i, l) can follow the closing '/'. These patterns are treated as RegExp objects. ```TJS2 /[0-9]-[0-9]-[0-9]/ /^;\s*(.*?)\s*=(.*)$/ /start(.*?)end/gi ``` -------------------------------- ### TJS2 Numeric Literals with Fractional Parts and p-Exponents Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples showing how fractional parts and 'p' (for base-2 exponents) can be used in hexadecimal, octal, and binary numeric literals in TJS2. ```TJS2 0b1.1 // 1 + 1/2 で 1.5 を表す 0x2.f // 2 + 15/16 で 2.9375 を表す 0x1p8 // 1 × 28 で 256.0 を表す ``` -------------------------------- ### Implementing Page Break in KAG Script Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Letter.html Illustrates how to clear the message layer and start a new page of text using the [p] tag for a click wait before clearing and the [cm] tag to perform the clear. ```KAG Script [wait time=200] *start|スタート [cm] こんにちは。[l][r] ごきげんよろしゅう。[l][r] 改ページしますよ。[p] [cm] 改ページしました。 ``` -------------------------------- ### Complex Right-Click Menu Subroutine in KAG Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/RClick.html Implements a comprehensive right-click menu in KAG. It includes options to hide messages, view history, load/save bookmarks, return to the start, and exit the menu, demonstrating advanced state saving, layer control, and link usage. ```KAG *sub1 @tempsave ; ↑一時的に状態を保存 @history output=false ; ↑メッセージ履歴への出力を無効に @mapdisable layer=0 page=fore ; ↑クリッカブルマップをもし使っている場合はこのようにして無効化する @backlay @layopt layer=message1 page=back visible=true ; ↑このサブルーチン内ではメッセージレイヤ1を使う @layopt layer=message0 page=back visible=false @current layer=message1 page=back @position left=0 top=0 width=640 height=480 @eval exp="f.r_first=true" ; ↑このルーチンに入ったときにだけトランジションを行うように ; *menu @er @nowait [link target=*hide]メッセージを消す[endlink][r] [link target=*history]メッセージ履歴を見る[endlink][r] [link target=*load]栞をたどる[endlink][r] [link target=*save]栞をはさむ[endlink][r] [link target=*gotostart]最初に戻る[endlink][r] [link target=*ret]戻る[endlink][r] @endnowait @current layer=message1 page=fore @if exp="f.r_first" @trans time=500 rule=trans1 vague=128 @wt @endif @eval exp="f.r_first=false" @s *ret ; サブルーチンから戻る @tempload bgm=false se=false backlay=true @trans time=500 rule=trans1 vague=128 @wt @return *hide ; メッセージを消す @hidemessage @jump target=*menu *history ; メッセージ履歴を見る @showhistory @jump target=*menu *load ; 栞をたどる ; emb exp= .... については [TJSをもっと使うために](TJSTips.html) を参照 @er @nowait [link target=*lt0][emb exp="kag.getBookMarkPageName(0)"][endlink][r] [link target=*lt1][emb exp="kag.getBookMarkPageName(1)"][endlink][r] [link target=*lt2][emb exp="kag.getBookMarkPageName(2)"][endlink][r] [link target=*lt3][emb exp="kag.getBookMarkPageName(3)"][endlink][r] [link target=*lt4][emb exp="kag.getBookMarkPageName(4)"][endlink][r] [link target=*menu]戻る[endlink][r] @endnowait @s *lt0 @load place=0 ask=true @jump target=*menu *lt1 @load place=1 ask=true @jump target=*menu *lt2 @load place=2 ask=true @jump target=*menu *lt3 @load place=3 ask=true @jump target=*menu *lt4 @load place=4 ask=true @jump target=*menu *save ; 栞をはさむ ; emb exp= .... については [TJSをもっと使うために](TJSTips.html) を参照 @er @nowait [link target=*st0][emb exp="kag.getBookMarkPageName(0)"][endlink][r] [link target=*st1][emb exp="kag.getBookMarkPageName(1)"][endlink][r] [link target=*st2][emb exp="kag.getBookMarkPageName(2)"][endlink][r] [link target=*st3][emb exp="kag.getBookMarkPageName(3)"][endlink][r] [link target=*st4][emb exp="kag.getBookMarkPageName(4)"][endlink][r] [link target=*menu]戻る[endlink][r] @endnowait @s *st0 @save place=0 ask=true @jump target=*menu *st1 @save place=1 ask=true @jump target=*menu *st2 @save place=2 ask=true @jump target=*menu *st3 @save place=3 ask=true @jump target=*menu *st4 @save place=4 ask=true @jump target=*menu *gotostart ; 「最初に戻る」 @gotostart ask=true @jump target=*menu ``` -------------------------------- ### Evaluating TJS Expressions with eval (KAG) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Tags.html Shows various examples of using the [eval] tag to evaluate TJS expressions, including assigning numbers and strings to game variables (f.) and system variables (sf.), and performing calculations. ```KAG 例: [eval exp="f.test=500"] ;↑ゲーム変数 test に数値を代入している [eval exp="f.test2='文字列'"] ;↑ゲーム変数 test2 に文字列を代入している [eval exp="sf.test=400"] ;↑システム変数 test に数値を代入している [eval exp="f.test2=f.test*3"] ;↑ゲーム変数 test2 に ゲーム変数 test の 3 倍の数値を代入している ``` -------------------------------- ### CDDASoundBuffer.onFadeCompleted Event Syntax (TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_CDDASoundBuffer_onFadeCompleted.html This is the syntax for the onFadeCompleted event handler of the CDDASoundBuffer class. This event is triggered when a sound fading operation, started by the fade method, finishes. ```TJS onFadeCompleted() ``` -------------------------------- ### Defining Scenario Parts with Labels and [s] Tag (KAG Script) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/ReadUnread.html This snippet illustrates how KAG divides a scenario into 'parts' for unread/read tracking. Each part typically starts at a label (`*`) and ends at the next label or an `[s]` tag. The status of each part is recorded in a system variable. ```KAG Script *部分その1 @cm ここは部分その1です。[l][r] 普通は次のラベルまでが一つの「部分」となります。[p][r] *部分その2 @cm ここは部分その2です。[p][r] *部分その3 @cm ここは部分その3です。[l][r] [[s]タグまでも一つの「部分」となります。[s] ``` -------------------------------- ### Syntax of freeDirectSound Method (KAG/TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_WaveSoundBuffer_freeDirectSound.html This snippet shows the basic syntax for the freeDirectSound method. It is a method of the WaveSoundBuffer class and takes no arguments. ```KAG/TJS freeDirectSound() ``` -------------------------------- ### Check String Contains Substring (indexOf) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Checks if the variable `f.objname` contains any of the characters '尼', '屁', or '尻' by searching within the combined string '尼屁尻'. Executes the block if found. ```KAG/TJS [if exp="'尼屁尻'.indexOf(f.objname)!=-1"]~~[endif] ``` -------------------------------- ### Creating Choices with Link Tags (Clearing Screen) - KAG Script Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Diverge.html An improved example demonstrating how to clear the message layer and remove the choices from the screen after a selection is made. This is achieved by adding the [cm] tag immediately after the target label definition. ```KAG Script [wait time=200] *start|スタート [cm] [link target=*select1]選択肢1[endlink][r] [link target=*select2]選択肢2[endlink][r] [link target=*select3]選択肢3[endlink][r] [s] *select1 [cm] 選択肢1が選択されました。[l] [s] *select2 [cm] 選択肢2が選択されました。[l] [s] *select3 [cm] 選択肢3が選択されました。[l] [s] ``` -------------------------------- ### Define Basic Macro (Single Line) - KAG Script Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Macro.html Defines a simple macro named 'newtag' that replaces the tag with red text. This example shows a single-line definition for conciseness. ```KAG Script [wait time=200] *start|スタート [cm] ; -- マクロの定義 -- _[macro name=newtag]_[font color=0xff0000]こんな風にマクロを作ります[resetfont]_[endmacro]_ ``` -------------------------------- ### Logging Variable to Console (KAG) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Tags.html This KAG script snippet uses the `[trace]` tag to output the value of the game variable `f.test` to the console. The console can be displayed with Shift+F4 or logged to a file by setting `logMode` in `Config.tjs`. The example shows the expected console output format. ```KAG [trace exp="f.test"] ``` -------------------------------- ### Performing Universal Layer Transition (KAG) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Tags.html This KAG script snippet demonstrates a typical sequence for a universal layer transition. It first copies the front page to the back page using `[backlay]`, loads an image onto layer 0 on the back page using `[image]`, initiates a universal transition over 1500ms with a specific rule image and vagueness using `[trans]`, and finally waits for the transition to complete using `[wt]`. ```KAG [backlay] [image storage=fg0 layer=0 page=back] [trans method=universal time=1500 rule=trans0 vague=64] [wt] ``` -------------------------------- ### Applying Universal Background Transition (KAG) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Trans.html This snippet shows how to perform a universal transition on the background layer. It first sets up the initial background, waits, clears the message area, copies the foreground page to the background page, loads a new background image onto the background page, performs a universal transition using a specified rule image, and then waits for the transition to complete. ```KAG [image storage="bg0" page=fore layer=base] [wait time=200] *start|スタート [cm] こんにちは。背景レイヤを切り替えます。[l][r] _[backlay]_ [image storage="bg1" layer=base _page=back_] _[trans method=universal rule="rule1" vague=1 time=1500]_ _[wt]_ 切り替わりましたか? ``` -------------------------------- ### Re-throwing and Handling Exceptions in Nested TJS Functions Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/try.html This example illustrates a scenario where an exception caught in one function (`tryloadimage`) is re-thrown (`throw e`) to be caught by a higher-level caller function (`test`). This allows for localized handling (like logging) while still propagating the error. ```TJS function tryloadimage() { try { primaryLayer.loadImages("test1.bmp"); // test1.bmp を読んでみる } catch(e) { inform("画像読み込みに失敗しました。"); throw e; // メッセージを表示はするが、例外を再び投げる } } function test() { // tryloadimage を呼び出し、画像読み込みが成功すれば true // そうでなければ false を返す関数 try { tryloadimage(); } catch { return false; } return true; } ``` -------------------------------- ### Check String Contains Specific Characters (indexOf with \v) - KAG/TJS Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/TJSTips.html Checks if the variable `f.objname` contains exactly '尼', '屁', or '尻' by searching within the string '尼\v屁\v尻' delimited by the vertical tab character (\v). This prevents matching combined strings like '尼屁'. Executes the block if found. ```KAG/TJS [if exp="'尼\v屁\v尻'.indexOf(f.objname)!=-1"]~~[endif] ``` -------------------------------- ### Read Status with [link], @wait, and @jump (KAG Script) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/ReadUnread.html This example shows how scenario control tags affect read status. When a user selects a choice via a `[link]` tag or a `[jump]` tag is executed, the current scenario 'part' is typically marked as read at that point. The `contpage` attribute can modify this behavior. ```KAG Script *select ここの部分は、ユーザが選択肢を選択した時に既読になります。[r] [link target=*t1]選択肢1[endlink][r] [link target=*t2]選択肢2[endlink][r] @wait time=3000 @jump target=*timeout ``` -------------------------------- ### Basic Text Display in KAG Script Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Letter.html Shows the initial content of the first scenario file (first.ks) demonstrating simple text output. ```KAG Script [wait time=200] *start|スタート [cm] こんにちは。 ``` -------------------------------- ### Changing Message Assignments with System.assignMessage (KrkrZ/Krkr2) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_System_assignMessage.html Changes the assignment of internal messages. This method allows overriding built-in messages with custom ones. It is typically used within message map files (see Startup). To get a list of configurable IDs and their current assignments, execute 'Create Message Map File' from the Controller. Parameters: - id: Specifies the message ID to assign. - msg: Specifies the message to assign to the ID specified by id. Return Value: Returns true if the ID exists and the message assignment is successful, otherwise returns false. ```KrkrZ/Krkr2 Script assignMessage(id, msg) ``` -------------------------------- ### Calling WaveSoundBuffer.freeDirectSound (KAG/TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_WaveSoundBuffer_freeDirectSound.html This snippet demonstrates how to call the freeDirectSound method. It must be called directly on the WaveSoundBuffer class itself, not on an instance object. ```KAG/TJS WaveSoundBuffer.freeDirectSound(); ``` -------------------------------- ### TJS2 Hexadecimal Numeric Literals Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples of hexadecimal numeric literals in TJS2, which are prefixed with '0x' or '0X'. ```TJS2 0x1234 0Xff 0x3f33 ``` -------------------------------- ### Using Storages.selectFile to open a file (TJS) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_Storages_selectFile.html This snippet demonstrates how to use `Storages.selectFile` to display a file open dialog. It configures the dialog with specific file filters (text and binary), sets the initial filter index, provides an initial directory (the executable path), sets a custom title, and specifies it as an 'Open' dialog. After the user interacts with the dialog, it checks the return value; if the user pressed OK, it displays the selected file name using `System.inform`. ```TJS var params = %[\n filter : [ "テキストファイル(*.txt)|*.txt", "バイナリファイル(*.bin)|*.bin" ],\n filterIndex : 1,\n name : "",\n initialDir : System.exePath,\n title : "ファイルを開く",\n save : false,\n ];\n if(Storages.selectFile(params))\n System.inform("選択したファイルは : " + params.name); ``` -------------------------------- ### Layer.affinePile メソッド構文 Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/f_Layer_affinePile.html LayerクラスのaffinePileメソッドの構文とパラメータです。このメソッドは、ソースレイヤの指定された領域をアフィン変換して現在のレイヤに重ね合わせます。affineパラメータによってA~Fの解釈が変わります。opaで不透明度、typeで補間方法を指定しますが、typeは現在stNearestのみサポートされています。このメソッドは非推奨です。 ```KAG/TJS affinePile(src, sleft, stop, swidth, sheight, affine, A, B, C, D, E, F, opa=255, type=stNearest) ``` -------------------------------- ### Displaying, Changing, and Hiding Foreground Layer with Crossfade (KAG) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kag3doc/contents/Trans.html This comprehensive snippet illustrates how to manage a foreground layer's visibility and content using crossfade transitions. It shows the process of displaying a foreground image, replacing it with another, and finally hiding it. Each step involves copying the current state to the background page (`backlay`), modifying the target layer on the background page, and then applying a crossfade transition (`trans method=crossfade`) to make the changes visible on the foreground page. ```KAG [image storage="bg0" page=fore layer=base] [wait time=200] *start|スタート [cm] こんにちは。前景レイヤをトランジションを使って表示させます。[l][r] [backlay] [image layer=0 page=back storage="fg0" visible=true] ; この時点で、表ページの前景レイヤ 0 は(デフォルトのままなので)不可視、 ; この時点で、裏ページの前景レイヤ 0 は可視で画像を保持していて、 ; 他の裏ページのレイヤは backlay タグの効果で、すべて表ページと同じ [trans method=crossfade time=1500][wt] つぎは、前景レイヤを入れ替えます。[l][r] [backlay] [image layer=0 page=back storage="fg1" visible=true] ; この時点で、裏ページの前景レイヤ 0 は fg1 という画像、 ; 他の裏ページのレイヤは backlay タグの効果で、すべて表ページと同じ [trans method=crossfade time=1500][wt] そうしたら、前景レイヤを消します。[l][r] [backlay] [layopt layer=0 page=back visible=false] ; この時点で、裏ページの前景レイヤ 0 は不可視、 ; 他の裏ページのレイヤは backlay タグの効果で、すべて表ページと同じ [trans method=crossfade time=1500][wt] ``` -------------------------------- ### TJS2 Interpolated Strings (@-Strings) Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples of @-strings in TJS2, where expressions enclosed in '&...;' or '${...}' are evaluated and their results are embedded directly into the string. Backslashes can escape '&' or '$'. ```TJS2 @"1+2=&1+2;" ( "1+2=3" という文字列になる ) @"変数 f の内容は &f; です" ( 変数 f の内容を &f; の場所に展開する ) @"関数 func を呼び出した結果は &func(); です" ( 式として有効なものならば & と ; の間に記述可 ) @"関数 func を呼び出した結果は ${func()} です" ( 上と同じ ) @"true \&\& false は &true && false;" ( & の前に \ を書けば & は展開されない ) ``` -------------------------------- ### TJS2 String Literals Source: https://github.com/krkrz/krkr2doc/blob/master/docs/tjs2doc/contents/token.html Examples of string literals in TJS2, which can be enclosed in either double ('"') or single (''') quotes. The other quote type does not need to be escaped within the string. ```TJS2 "this is a string." 'this is also a string.' "Can't use without a quotation." ``` -------------------------------- ### Using Universal Transition with @trans Tag in KAG Source: https://github.com/krkrz/krkr2doc/blob/master/docs/kr2doc/contents/Transition.html This KAG snippet demonstrates applying the 'universal' transition using the @trans tag. It specifies the target layer ('base'), includes child layers ('children=true'), sets the method ('universal'), and provides transition-specific options like vague, time, and rule as tag attributes. ```KAG @trans layer=base children=true method=universal vague=100 time=2000 rule=rule1.png ```