document

Basic definition file
Simple variables
Array variables
Dictionary variables
Optional parameters for dictionary variables
preprocess symbol
System symbols
System variables (passive)
System variables (active)
System functions
Error/debug output
Comments
Encrypted
SAORI
Points to note, trivia, etc.

Basic definition file


misaka.ini is the basic definition file. The following entries exist.


dictionaries
{
misaka.txt
hoge.txt
data\misaka.txt
}

debug,0
debugsaori,0
error,0
propertyhandler,0


dictionaries The read files are listed as dictionary files in the breath. Relative paths can also be used. There are no restrictions on the file names that can be used.

debug specifies whether to output debug output using a bool value. The debug output is saved in Misaka's home directory under the name misaka_debug.txt, and a log is recorded that is useful for investigating the final processing line in the event of abnormal behavior. Note that this process (mainly writing to disk) is extremely heavy, so it should be turned on only when necessary. Default value is 0 (OFF).

debugsaori specifies whether to output SAORI debugging using a bool value. The SAORI debug log is saved in Misaka's home directory under the name misaka_debugsaori.txt. Currently, only request and response logs are recorded. Default value is 0 (OFF).

error specifies whether to detect/output simple grammar errors during preprocessing with a bool value. The debug output is saved in Misaka's home directory as his misaka_error.txt. Default value is 0 (OFF).

propertyhandler specifies whether the property handler can be used with a bool value. Property handlers are certainly useful, but they make the control path very complex, which is a big drawback for debugging in the development environment and for tracing with misaka_debug.txt. Also, property handlers are called every time a variable changes, so they are theoretically heavy (though not visibly heavy). Therefore, if you know from the beginning that you will not use it at all, it is better to turn it off. Default value is 0 (OFF).

simple variable


You can freely create and use variables at any time. Variables have no type and are determined at the time of use. If you try to treat a string that cannot be interpreted as a number as a number, it will be evaluated as 0.

bool values are treated as predefined strings true and false.

It can only handle positive and negative integers, and cannot handle decimal numbers.

Add double quotes to string literals.


To assign a value to a variable, use the following syntax. If the variable does not yet exist at the time of assignment, a new variable is created.


  • simple assignment


    A simple value assignment is performed by connecting with =. illustration

    {$z=128}
    {$nyo="nyo"}

    When assigning a string, you must always double quote it.


  • Arithmetic assignment

    If the right-hand side is a mathematical expression, the result of the calculation is substituted. illustration

    {$z=(1+1)*4}

    Here is the importance of quotes. If you write something like the following, it will be treated as a string that just looks like a mathematical formula, and no calculations will be performed.

    {$z="(1+1)*4"}


  • Simple operation assignment


    You can also use C-like abbreviations such as:

  • {$z++}
  • {$z--}
  • {$z+=n}
  • {$z-=n}
  • {$z*=n}
  • {$z/=n}

    From above, add 1 to $z, subtract 1 from $z, add n to $z, subtract n from $z, multiply $z by n, and divide $z by n.


  • Evaluation (value extraction)


    To retrieve a value from a variable, use the following syntax:

    {$z}

    Evaluations can be made at any time and can be nested infinitely. illustration

    {$z=({$a}+1)*{$b}}


    Several system functions are defined that are useful for controlling variables. See section System Functions.

    Simple variables are subject to automatic save/restore. The variables held at the time of termination will be restored with the same values the next time the program is started.

  • Array variables


    You can freely create array variables. Array variables are basically the same as simple variables, except that they have multiple values.

    At the declaration stage, there is no descriptive difference between simple variables and array variables. for example

  • {$list=""}

    This empties the array variable $list.

    Use the system function append to add values to array variables.

  • {$append($list,"AIUEO")}
  • {$append($list,"Kakikukeko")}

    If you refer to a variable that has become an array in this way without any arguments, one will be returned at random from the entire list. In other words, if you execute {$list} after performing the processing in the above two lines, a random character string such as "Aiueo'' or "Kakikukeko'' will be returned.

    To get a string at a specific position, use square brackets and give a subscript.

  • {$list[1]}

    This always returns "Kakikukeko".


    There is no limit to the maximum number of arrays.

    Several system functions are defined that are useful for controlling array variables. See section System Functions.

    Array variables are also subject to automatic save/restore like simple variables.

  • Dictionary variables


    The variables read from the dictionary file at startup are called dictionary variables, which are similar in structure to array variables, but have the following special properties.


    0. Read only

    1. Can have recruitment condition expressions


    Other than these two points, dictionary variables are treated no differently than array variables.

    Dictionary variables can be used in the same way as regular array variables in system functions that control array variables. However, in this case, the dictionary variable is treated as a normal array variable, and the above characteristics are temporarily lost.

    Optional parameters including dictionary variable employment condition expressions


    Dictionary variables, unlike regular variables, can have several optional parameters.


  • logical expression


    Dictionary variables with logical formulas are variables for which inclusion conditions exist and are frequently used to maintain diversity in event responses. The logical expression is written as follows.


    $OnBoot; {$if ({$hour}==12)};
    \0\s0Start-up, 12 o'clock. \e
    
    $OnBoot
    \0\s0Other than that.\e
    
    If such a definition is made in the dictionary, the upper variable will be used when the current time is 12, and the lower variable will be used at other times. By using this kind of structure, you can easily return various responses to the same event.

    Symbols are evaluated in the order of their definition (the one closest to the beginning of the file, or the one included first when multiple files are included). Misaka uses this structure when she constructs an if else nest. Therefore, an unconditionally adopted dictionary variable without any logical formula must be defined the latest (if an unconditionally adopted dictionary variable is declared first, the dictionary variables declared after that are always).

    Parameters are "logical expressions" and do not necessarily have to be in $if syntax. For example, the following formula is also correct.

    $Dummy; {$stringexists({$array},{$s})};
    \0\s0It already exists. \e
    
    $Dummy
    \0\s0No.\e
    
  • nonoverlap


    A dictionary variable with the nonoverlap parameter specified will never have duplicate retrieved elements until all elements have gone through one cycle. However, it is still randomly obtained from all elements. This property is mainly used to block duplication of random talk. illustration

    $_OnTalkCore; nonoverlap;
    A
    B
    C
    D
    E
    F
    
    $_OnTalkCore returns a random string from the list every time it is called like a normal dictionary variable, but even if it is called continuously, no duplicate elements will be returned until all elements appear, such as "ADBFEC" and "CFADEB".


  • sequential


    Dictionary variables for which the sequential parameter is specified are always read sequentially starting from element 0, and once all elements have gone through, the process returns to 0 again and repeats the process. This property is mainly used to control a series of sentences that are spoken consecutively at certain intervals. illustration

    $_alphabet; sequential;
    A
    B
    C
    D
    E
    F
    
    $_alphabet returns strings in the order ABCDEFABCDEF... each time it is called.


    All parameters can be duplicated any number of times. There is no problem in specifying logical expressions and nonoverlap etc. at the same time. If you specify more than one, enumerate them as follows.

    $OnBoot; {$if ({$hour}==12)}; nonoverlap;
    
    However, if the combination of parameters is not logically consistent, one of the parameters may become invalid. For example, nonoverlap and sequential cannot be used at the same time because their operations conflict.

  • preprocess symbol


  • #_Common

    A logical expression declared with the #_Common symbol is added to all symbols in the file using the relational operator &&. This structure is mainly effective for ghosts with multiple modes. In other words, if you write a mode judgment expression in #_Common, you no longer need to write any mode judgment expressions in that file, and you can realize multiple modes by simply dividing the file. illustration

    #_Common
    {$if ({$mode}==0)}
    
    The logical expression {$if ({$mode}==0)} is added to all symbols in the file.

  • System symbol


    General event handling symbols that begin with On automatically become system symbols. This is defined in the form of $id, and all SHIORI/3.0 reserved words are used as is, so we will omit the explanation.

  • $OnNotify_*

    When a NOTIFY request arrives, Misaka first performs the minimum processing required by the kernel, such as creating an appropriate system variable from the Reference argument, and then executes the user code with the symbol $OnNotify_id. The Reference argument remains as she received the NOTIFY. Furthermore, due to the nature of the NOTIFY request, even if she returns the script here, it will be discarded.

  • $_Variable
  • $_Constant

    $_OnVariable is called immediately after Misaka starts up/just before the automatic return of user variables, and mainly performs the process of setting default values for all variables. It can be thought of as a global variable declaration section. All of Misaka's variables do not need to be declared and are of variant type, but it is thought that readability will be improved if variables that are truly global are declared here (although this is not required).

    $_OnConstant is called immediately after Misaka starts up/immediately after the automatic return of user variables, and performs forced initialization of variables whose automatic return should be ignored. It can be thought of as a global constant declaration section.


    $_OnGhostCommunicateReceive

    Called when spoken to by another ghost. You can check who spoke to you and what lines they used by combining the system variable {$sender} and the system function {$insentence} {$inlastsentence}.


    $_OnRandomTalk

    Called at approximately 0.5 to 1.5 times the interval specified by the system variable $_talkinterval. Describe so-called "random talk".

  • System variables (passive)


    The following variable names are predefined at the system level and are always updated automatically. Users must not redefine variables with the same name as environment variables.


  • $year / $month / $day / $hour / $minute / $second / $dayofweek

    Current year, month, day, hour, minute, second, day of the week. Day of the week: 0 is Sunday and 6 is Saturday.

  • $elapsedhour / $elapsedminute / $elapsedsecond

    Continuous activation time of Ghost. hours, minutes, and seconds, respectively.

  • $elapsedhouros / $elapsedminuteos / $elapsedsecondos

    Continuous OS boot time. hours, minutes, and seconds, respectively.

  • $elapsedhourtotal / $elapsedminutetotal / $elapsedsecondtotal

    Ghost's total startup time. hours, minutes, and seconds, respectively.

  • $os.version

    OS version number.

  • $os.name

    Common OS name 'Windows 2000'

  • $os.phisicalmemorysize

    The total amount of physical memory managed by the OS. Unit byte.

  • $os.freememorysize

    Physical memory free space managed by the OS. Unit byte.

  • $os.totalmemorysize

    Total available memory capacity, including virtual memory, managed by the OS. Unit byte.

  • $cpu.vendorname

    The name of the vendor of the CPU currently running. "Intel" etc.

  • $cpu.name

    Generic name of the currently running CPU. "Athlon", "Pentium III", etc.

  • $cpu.clockcycle

    The clock of the currently running CPU. Unit: Mhz.

  • $daysfromlastupdate

    Number of days since the last network update. Unit: day. illustration

    $_OnBoot; {$if (7<={$daysfromlastupdate})};
    \0\s0I want to update the network soon.\e
    
    $_OnBoot \0\s0Usually. \e
    In the above example, if 7 days have passed without updating the network, you will be prompted to update.

  • $daysfromfirstboot

    Number of days that have passed since the first startup. Unit: day.

  • $lastsentence

    The other party's script received in the previous COMMUNICATE. Exactly the same as what the $inlastsentence function compares.

  • $otherghostlist

    Array. A list of other ghosts currently on the same desktop. If you are the only one, null.

  • $hwnd.sakura / $hwnd.kero / $hwnd.sakuraballoon / $hwnd.keroballoon

    For each HWnd

  • System variables (active)


    The following variable names are predefined at the system level and are used for special purposes. Users must not redefine variables with the same name as environment variables.


  • $to

    Addressing name for anti-ghost communications. By setting the target ghost name in this variable and then speaking, the message will be delivered to the other party. illustration


    {$to=Hana-chan}\0\s0Hello.


    The variable $to is reset every time you speak.


  • $_talkinterval


    Interval at which the system symbol $_OnRandomTalk is called. Unit second.

  • System functions


    The following function names are predefined at the system level and are always evaluated as functions. Users must not redefine variables with the same name.


    Evaluation functions


  • {$if [ifelement] { [true] } else {false}}

    if syntax. Evaluates the logical expression and returns a bool value or script within each breath. illustration

    \0\s0{$if (({$month}==12) && (({$day}==24) || ({$day}==25))) { Christmas } else { Just a day }}\e

    If the current time is December and it's the 24th or 25th, this script will say "Christmas", otherwise it will say "just a day".

    Relational operators are == <= >= < > !=
    Logical operators are && ||

    There is no limit to complexity; you can combine any number of logical expressions as long as the format is followed.


    The processing section after the logical expression can be omitted. If the elements after else are omitted and the logical expression is false, the $if part becomes blank (disappears). Also, if you omit the processing part completely, $if returns the bool value itself. Therefore, the following expressions are all valid expressions.

    {$if (({$hour}==9) || ({$minute}==59))}¤Ë¤ç¡¼¤ó¡£\e
    {$if (({$hour}==9) || ({$minute}==59)) { ÉÔºÙ¹©{$hour} } else { ÉÔºÙ¹©¤¸¤ã¤Ê¤¤ }}¤Ë¤ç¡¼¤ó¡£\e
    {$if (({$hour}==9) || ({$minute}==59)) { ÉÔºÙ¹©{$hour} }}¤Ë¤ç¡¼¤ó¡£\e
    {$if (({$hour}==9) || ({$minute}==59)) { ÉÔºÙ¹©{$if ({$hour}==9)} }}¤Ë¤ç¡¼¤ó¡£\e


    Below are some points to keep in mind.


    Enclose each expression in completely independent parentheses.

    {$if ({$month}==12 && ({$day}==24 || {$day}==25))}

    is a way of writing in the C language, and the C compiler actually passes this format, but Misaka's format is incorrect. Correctly

    {$if (({$month}==12) && (({$day}==24) || ({$day}==25)))}

    However, if the relational operators are the same, multiple logical expressions can be placed within one parenthesis. Therefore, the following formula is valid.

    {$if ({$month}==12 && {$day}==24 && {$hour}==0)}


    Spaces cannot be omitted.

    If there is too much space, it can be filled in, but if there is not enough space, it may run out of control. Illustration of a mistake

    
    {$if(({$month}==12) && (({$day}==24) || ({$day}==25))) {¥¯¥ê¥¹¥Þ¥¹} else {¤¿¤À¤ÎÆü}}
    
    
    Basic function


  • {$reference(n)}

    Returns the contents of the current nth reference header.


  • {$random(n)}

    Returns a random number (integer) in the range 0 to n-1.


  • {$calc(expression)}

    Calculates the four arithmetic expressions indicated by expression and returns the result. Expressions can be written with multiple terms/operation priority can be controlled using parentheses. illustration

    {$calc(1+1)}
    {$calc(1+1*2)}
    {$calc((1+1)*2)}
    {$a=1}{$b=2}{$c={$calc({$a}*5+{$b}*10)}}{$c}

    Operators that can actually be used

    + addition
    - subtraction
    * multiplication
    / division
    % remainder
    ^ power

    There is no concept of decimal points. If the division results in a decimal number, it is truncated.


    String function


  • {$extractfilename(s)}

    Treats the string s as a file name, removes the path and returns only the file name.

    C:\hoge\hoge.txt ¢ª hoge.txt


  • {$index(n,s)}

    Finds string n in string s and returns its starting position. Unit byte. illustration

    {$index("hum","human")}
    {$index("hux","human")}
    {$index("n","human")}


  • {$insentence(s,n,n,n,n....)}

    Searches for string n in string s and returns a bool value indicating whether all of them exist. Maximum number of arguments is infinite.

    Note that the order of the arguments is reversed from index.

    {$insentence("human","hum")}
    {$insentence("human","hux")}
    {$insentence("human","hum","uma","u")}
    {$insentence("human","hum","hua")}


  • {$inlastsentence(n,n,n,n....)}

    Encapsulation function for insentence. Insentence is determined for lastsentence (the other party's script received in her previous COMMUNICATE).


  • {$length(s)}

    Returns the length (in bytes) of string s.


  • {$substring(s,offset,count)}
  • {$substringl(s,count)}
  • {$substringr(s,count)}

    Returns a substring of string s. substring is count bytes from the offset byte of string s, substringl is count bytes from the left end of string s, and substringr is count bytes from the right end of string s.


  • {$substringw(s,m,n)}
  • {$substringwl(s,n)}
  • {$substringwr(s,n)}

    Wide character version substring. Count the apparent number of characters instead of the number of bytes. Other than that, same as substring. illustration

    {$temp="¤¢a¤¤b¤¦c¤¨d¤ª"}{$substringl({$temp},3)}
    {$temp="¤¢a¤¤b¤¦c¤¨d¤ª"}{$substringlw({$temp},3)}

    ¾å¤Î·ë²Ì¤Ï¡Ö¤¢a¡×¡¢²¼¤Î·ë²Ì¤Ï¡Ö¤¢a¤¤¡×


  • {$substringfirst(s)}
  • {$substringlast(s)}

    Encapsulation function for substringw. substringfirst returns the first character of s, substringlast returns the last character of s. This function is MBCS-aware (compares characters rather than bytes).


  • {$hiraganacase(s)}

    Returns all hiragana characters from the string s that contains katakana characters. Items that cannot be converted, such as kanji, are left as is.


  • {$isequallastandfirst(s0,s1)}

    Determines whether the last character of s0 and the first character of s1 are the same and returns a bool value. This function is MBCS-aware (compares characters rather than bytes).


  • {$getvalue(n,m)}

    Separates the string passed in n with commas and returns the nth element.

    {$_ref="a,b,c,d,e,f"}{$getvalue("{$_ref}",3)}

    The value of this expression is d


  • {$getvalueex(n,m)}

    Separates the string passed in n by byte value 1 and returns the nth element.


    Array function


  • {$append(a,s)}

    Add element s to array variable a. If a is already a simple variable, its value as a simple variable becomes a[0], s becomes a[1], and a changes to an array variable.


  • {$copy(a0,a1)}

    Copy array variable a0 to a1. Dictionary variables can also be used for a0 under the following conditions.

    The recruitment conditional expression is ignored and the first dictionary variable found is used.


  • {$count(a)}

    Returns the number of elements in array a. Subscripts are valid up to the value -1 obtained by this function. If a is a simple variable, 1 is always returned. If a is neither an array variable nor a simple variable (NULL), -1 is returned.


  • {$pop(a)}

    Returns one element at random from array variable a and simultaneously removes that element from the array. Returns an empty string if the array is empty.


  • {$popmatchl(a,s)}

    Returns one element at random from among the elements of array variable a that match s in the left direction, and simultaneously deletes that element from the array. Returns an empty string if there are no matching elements.


  • {$stringexists(a,s)}

    Returns a bool value indicating whether there is an element in array variable a that exactly matches string s.


    SAORI functions


  • $loadsaori(filename)

    Loads and locks the SAORI DLL pointed to by filename.


  • $unloadsaori(filename)

    Unloads and unlocks the SAORI DLL pointed to by filename.


  • $saori(filename,arg0,arg1,arg2....)

    Executes the SAORI indicated by filename with arg set as the argument header. Blocks until the SAORI returns a response. It will crash if the specified DLL has not been loaded yet. It also crashes when an error occurs inside SAORI. illustration

    {$loadsaori("substr.dll")}
    {$temp={$saori("substr.dll","¤¢¤¤¤¦¤¨¤ª",2,3)}}{$temp}
    {$unloadsaori("substr.dll")}
    
    If substr.dll is the substr.dll currently bundled with Saori, "¤¢¤¤¤¦¤¨¤ª" is set in $temp.

    In the example above, it is executed at the same time as loading and unloaded at the same time as execution ends, but there is no rule that says it must be used this way. There is no problem even if you load it at the same time as Misaka starts (for example, using $_Constant), leave it in memory forever, and call it many times. Lifespan management of SAORI is left to the user.

    As long as you use general SAORI, there is no particular problem if you load all SAORI to be used at the same time as starting Misaka and leave them as they are. The benefits of detailed life management and the overhead during loading/unloading are omitted here.

    Note that there is no need to consider the behavior when Misaka exits with SAORI loaded (without explicitly unloading it). Misaka automatically unloads all loaded SAORI upon completion.


    Other functions


  • $choice(n,n,n,n,n,n....)

    Returns a random value from among the values passed as arguments. There is no limit to the maximum number of arguments. illustration

    {$choice("¤¢¤¤¤¦¤¨¤ª",{$b},256)}


  • $isghostexists(n)

    Returns a bool value indicating whether the ghost indicated by the string n currently exists on the same desktop.


  • search(n,n,n,n....)

    Randomly selects one symbol whose symbol name includes all the strings passed as arguments, evaluates the expression, and returns the return value. There is no limit to the number of arguments. illustration

    $_OnTest
    {$search("human","japan")}

    $_OnTest2
    {$search("male")}

    $human-male-japan
    A

    $human-female-japan
    B

    $human-male-korea
    C

    $human-female-korea
    D

    $_OnTest returns A or B, and $_OnTest2 returns A or C.


  • backup()

    No arguments. Back up all the information Misaka has on-memory by writing it to disk. The processing content is the same as the variable saving processing that is automatically performed at the end.


  • getmousemovecount(n,m)

    Returns the OnMouseMove count of the part indicated by part name m on side n. By determining this count, the sensitivity of the so-called "stroking response" can be controlled. illustration

    $OnMouseMove,{$if (64<={$getmousemovecount(0,"Bust")})}
    {$resetmovecount(0,"Bust")}\0\s0Chest stroking response.\e

    $OnMouseMove,{$if (32<={$getmousemovecount(0,"Bust")})}
    \0\s0Has a suspicious reaction when his chest is stroked. \e


  • resetmousemovecount(n,m)

    Resets the OnMouseMove count of the part indicated by part name m of site n to 0.

  • Error output/debug output


    Error output is written to Misaka's home directory with the names misaka_error.txt and debug output is misaka_debug.txt (the latter only when the debug switch is ON).

    misaka_error.txt is the syntax error output. When Misaka starts up, it performs a syntax check on the entire data and outputs lines containing mistakes to this file.

    misaka_debug.txt is runtime debug output. Misaka outputs all steps during movement to this file. Therefore, if Misaka halts or freezes while running for some reason, you can easily identify where the problem occurred by looking at this file.

    Comments


    Lines starting with // are treated as comments. Comments are guaranteed to be ignored no matter where they appear in the file.

    However, currently mid-sentence/end-of-sentence comments cannot be used (must begin with // at the beginning of the sentence).

    Comments do not affect operating speed or memory consumption during actual operation.

    Encryption


    When misakac.exe is executed, all *.txt files in the same directory are encrypted and output as *.__1. Although the __1 files are no longer plain text files, if you include these files in misaka.ini, they will be read as normal data files.

    This function is primarily intended to be used by ghost authors to express their intention to the outside world, "Do not read". We cannot guarantee or guarantee that your content will never be read by anyone.


    Misakac.exe will convert any file with a .txt extension, so if there are files unrelated to Misaka, such as readme.txt, in the same directory, you need to take care to remove them.

    SAORI


    See SAORI function in System Functions.

    An explanation of what SAORI is is omitted in this document.

    Overall trends, precautions, trivia, etc.


  • Do not equate uppercase and lowercase letters

    For example, variables $z and $Z are treated as completely different. Misaka does not consider lowercase and uppercase letters to be the same.


  • All data files are Shift_JIS

    Data files containing so-called double-byte characters should be written in Shift_JIS.


  • 0 Count by origin

    Most ordinal information is counted at the 0 origin.


  • String literals are double-quoted.

    {$_ref="a,b,c,d,e,f"}

    of

    {$_ref=a,b,c,d,e,f}

    should not be written.


  • If the format is incorrect, it will almost always crash.

    Even if it is wrong, we will not take care of it (internally) and make it work.


  • Brace {} means "evaluate"

    For example, even if there is a variable called $hour, if you just write it as $hour, it is just a string called $hour. It is evaluated and has a return value only when written as {$hour}.

    {$lasthour="$hour"}
    {$lasthour={$hour}}

    If you do this, the current time will be set to the variable lasthour in the lower example, but the string $hour itself will be set in the upper example.


  • Some functions take variables themselves

    There are cases where it is meaningless to pass a variable without evaluating it. For example, $append adds an element to an array, but at this time­

    {$append($z,"¤¢¤¤¤¦¤¨¤ª")}

    OF

    {$append({$z},"¤¢¤¤¤¦¤¨¤ª")}

    should not be written. In this case, $z is a variable itself, and its contents are not required.


  • Block start/end braces must be placed as separate lines.

    illustration

    $_OnTest {
    \0\s0\1\s0
    \0Hey\w8\w8
    \1\s0Hmm\w8\w8
    \0\n\n....\w8\w8no, it's fine. \w8\w8
    \1\n\n....\w8\w8what is it?
    \e
    }

    The above is incorrect. Correctly

    $_OnTest
    {
    \0\s0\1\s0
    \0Hey\w8\w8
    \1\s0Hmm\w8\w8
    \0\n\n....\w8\w8no, it's fine. \w8\w8
    \1\n\n....\w8\w8what is it?
    \e
    }

  • Back