YOLOL:jp
概要
YOLOLは、デバイスを制御・管理するためのプログラミング言語です。
コードはYOLOLチップに書かれており、チップソケットに挿入され、チップがメッセージを読み取って中継する。
このプログラミング言語は、既知の宇宙にあるほとんどすべてのデバイスのプログラミングと制御を可能にします。
基本情報
使い方
コードはプログラマブル・チップに書き込まれて実行され、データ・ネットワークに接続されたデバイスの監視と制御の両方に使用される。
コードの行は、上から下へと順番に実行され、最後の行が実行された後、チップのサイクルを繰り返します。ただし、スクリプトに特定の行を変更したり、実行を完全に停止したりするプログラムされた命令が含まれている場合はこの限りではありません。
要点:
- コードの実行は1行目から
- 1行目を読んだ後、チップの時間間隔に基づいて次の行に進む
- このプロセスは、2行目、3行目、4行目...と繰り返されます。
- チップは、最後の行が実行された後、再び1行目の実行を開始します。(最後の行にgoto文が含まれている場合や、実行が一時停止されている場合を除く)
このように、空行でも0.2秒を使用するので、短い実行遅延として使用することができます。(コメントのみの行は実質的に空行と同じです)
制限事項
- 行の実行には0.2秒かかります。
- 1行に入力できる文字数は最大70文字(コメント、スペースを含む)です。
- 一部の機能は、特定のYOLOLチップでのみ動作します。
*そのため、以下の例のようにゲーム内で動作しないことがありますのでご注意ください。
関連ページ
コマンドリファレンス
大文字小文字を区別しない
プログラミング言語は、大文字と小文字を区別しません。
つまり、次の2つのスクリプト例は、互いに同じ機能を持っています:
if ButtonState == 1 then DoorState = 1 end
IF buttonstate == 1 THEN doorstate = 1 END
- どちらのスクリプトも、buttonstateの値が1であれば、doorstateを1に設定します。
- プログラミング言語の文字は、小文字でも大文字でも書くことができます。
- 大文字小文字を区別せずに解析されます。
- このようにして、コードを少し整理することができます。
変数
- プログラミング言語の変数は弱い型付け(型の有効性を強制しない)で、2つのデータ型をサポートしています。固定小数点の10進数(0.001までの精度)と文字列です。
- 簡単に言うと、変数は文字列か数字のどちらかで導入することができ、前の変数の型が同一でない場合は、エラーを起こさずに前の変数の型を無視します。
- 各変数は常に単一の型ですが、必要に応じて暗黙のうちに変換されます。
- 初期化されていない変数のデフォルト値は0で、NULL値はサポートされていません。
- True/Falseは、0以外の数値と0の数値です。
- True =! 0
- False == 0
変数に値を代入すると、その変数は常に新しく代入された値の型に変換されます。
例:
ultimateAutopilot= 128.643
- この結果、変数 ultimateAutopilot には 128.643 という数値が格納されます。
ultimateAutopilot= "Error prone"
- この結果、変数 ultimateAutopilot は文字列変数 "Error prone" となり、数値 128.643 が削除されます。
小数点以下
プログラミング言語における数値は、64 ビット固定小数点の 10 進数である。 変数は10進数を小数点3桁の精度で保持します。 そのため、最大値の範囲(演算中も含む)は[-9223372036854775.808, 9223372036854775.807]となります。
Numeric values in the programming language are 64-bit fixed-point decimals.
The variables hold decimal numbers up to three decimal accuracy.
As a result, the maximum value range (even during operations) is [-9223372036854775.808, 9223372036854775.807]
pieVariable= 3.142
- The above script assigns a numeric value of 3.142 to the variable pieVariable.
- Supplying more precise values than the variables can store works, but doesn't affect the end result.
notPieVariable= 0.5772156649
- The above script attempts to assign a numeric value of 0.5772156649 to the variable notPieVariable.
- The end result however is notPieVariable == 0.577
- Here, the more precise values are cut, leaving only three decimals behind.
Strings
To specify a string literal in the programming language, the desired string value must be surrounded with double quotation marks.
badRobots= "saltberia"
- This script assigns the string value of "saltberia" to the variable badRobots.
Device fields / External variables
External variables and device fields can be used in the programming language with the following syntax:
- :variableName
- variableName being the configured device field id.
A colon prefix : is used to tell the script that an external variable is being accessed, instead of using one that may or may not be declared or used in the script.
A programmable chip that is connected to a device has access to all the devices in the same network.
It can then modify and listen to any device fields it has access to.
if :ButtonState == 1 then :DoorState = 1 end
- The script above will send the value of 1 to any devices listening to the device field DoorState if the value of ButtonState is 1 in the data network.
Naming Limitations
Currently variables containing keywords such as if or end can be parsed incorrectly, and must be avoided.
Operators and commands
Note that the available operators may be limited by the type of the programmable chip.
Basic chips have a limited selection of functions while more advanced ones can perform more complex operations natively.
Basic arithmetic and assignment operators
Basic arithmetic and assignment
Operation | Numeric operation | String operation | Chip availability |
---|---|---|---|
A + B | Addition | String A is appended by String B. | All |
A - B | Subtraction | The last appearance of String B in String A is removed from String A. | All |
A * B | Multiplication | Runtime error. The rest of the line is skipped. | All |
A / B | Division | Runtime error. The rest of the line is skipped. | All |
A ++ | PostIncrement (A=A+1) | Appends a space to String A. Evaluates to the original value. | All |
A -- | PostDecrement (A=A-1) | Removes the last character of the string. Results in runtime error when trying to remove "". Evaluates to the original value. | All |
++ A | PreIncrement (A=A+1) | Appends a space to String A. Evaluates to the modified value. | All |
-- A | PreDecrement (A=A-1) | Removes the last character of the string. Results in runtime error when trying to remove "". Evaluates to the modified value. | All |
A = B | Assignment (Variable A is set to the value of variable B) | Assignment | All |
A += B | Addition-assignment (A=A+B) | A is assigned the value of string-operation A+B | All |
A -= B | Subtraction-assignment (A=A-B) | A is assigned the value of string-operation A-B | All |
A *= B | Multiplication-assignment (A=A*B) | Runtime error. The rest of the line is skipped. | All |
A /= B | Division-assignment (A=A/B) | Runtime error. The rest of the line is skipped. | All |
A ^= B | Exponentiation-assignment (A=A^B) | Runtime error. The rest of the line is skipped. | Advanced, Professional |
A %= B | Modulo-assignment (A=A%B) | Runtime error. The rest of the line is skipped. | Advanced, Professional |
A ^ B | Exponentiation | Runtime error. The rest of the line is skipped. | Advanced, Professional |
A % B | Modulo | Runtime error. The rest of the line is skipped. | Advanced, Professional |
ABS A | Modulus (absol value) (A=A if A>=0, else A=-A) | Runtime error. The rest of the line is skipped. | Advanced, Professional |
A! | Factorial | Runtime error. The rest of the line is skipped. | Advanced, Professional |
SQRT A | Square root of A | Runtime error. The rest of the line is skipped. | Advanced, Professional |
SIN A | Sine of A (degrees) | Runtime error. The rest of the line is skipped. | Professional |
COS A | Cosine of A (degrees) | Runtime error. The rest of the line is skipped. | Professional |
TAN A | Tangent of A (degrees) | Runtime error. The rest of the line is skipped. | Professional |
ASIN A | Inverse sine of A (degrees) | Runtime error. The rest of the line is skipped. | Professional |
ACOS A | Inverse cosine of A (degrees) | Runtime error. The rest of the line is skipped. | Professional |
ATAN A | Inverse tangent of A (degrees) | Runtime error. The rest of the line is skipped. | Professional |
Logical operators
Logical operators are checks that identify if the statement is true or false.
All logical operations return either "0 for False" or "1 for True".
The NOT, AND, and OR keywords consider 0 to be falsy and anything not 0 to be truthy.
Operation | Numeric operation | String operation | Chip availability |
---|---|---|---|
A < B | Less than | returns 1 if String A is first in alphabetical order, returns 0 if not. | All |
A > B | Greater than | returns 0 if String A is first in alphabetical order, returns 1 if not. | All |
A <= B | Less than or equal to | returns 1 if String A is first in alphabetical order or identical to String B, returns 0 if not. | All |
A >= B | Greater than or equal to | returns 0 if String A is first in alphabetical order or identical to String B, returns 1 if not. | All |
A != B | Not equal to | returns 1 if String A is not equal to String B, 0 if it is. | All |
A == B | Equal to | returns 1 if String A is equal to String B, 0 if not. | All |
NOT A | Not | Returns 1 if A is 0, otherwise returns 0. | All |
A AND B | And | Returns 1 if neither A nor B are 0, otherwise returns 0. | All |
A OR B | Or | Returns 1 if either A or B is not 0, otherwise returns 0. | All |
Mixing variable types in operations
Mixing variable types in an operation handles the operation using all parameters as strings.
previouslyNumber= "10" + 15
- The above script results in previouslyNumber containing the string value "1015".
- Note that the involved parameters themselves don't change types, their values are just cast as strings for the purpose of the operation:
purelyNumber = 15 purelyString = "10" + purelyNumber
- When this script has executed, purelyString contains the string value of "1015", while purelyNumber still contains the numeric value of 15.
Goto
Goto syntax is used when the normal script reading order from 1->20 is not desired, or needs to be altered.
Goto is used with the following syntax:
- goto lineNumber
- lineNumber is the line which this command will take the script execution.
- Any remaining script that is on the same line after the goto-command will not be executed.
- using if statements before goto ignores goto syntax, assuming the if-statement is false
- Multiple goto commands can be added on the same line using conditionals, as False goto commands are skipped.
- Numeric values outside the [1,20] range are clamped to this range.
- Non-integer values are floored.
- String values will result in a Runtime Error.
- lineNumber is the line which this command will take the script execution.
if variable == 5 then goto 4 end goto 6
The script above will go to line number 4, if variable has a value of 5.
Otherwise it will go to line number 6. Numerical operations can also be done "inside" the goto, e.g.
goto 4+1
If-else conditional
If-else statements are used to branch out the script into different paths.
They use the following syntax:
- if condition then statement else statement end
- Condition is a statement that results in a numeric value (where 0 is parsed as False, anything else as True), and statements are pieces of script that are run.
- All If-else conditional stations must have end syntax written after statement is complete.
If can be used to branch script execution into two possible outcomes temporarily based on variable value(s).
Example:
if variable != 2 then endResult = 3 else endResult = 4 end
- This script sets the value of endResult to 3 if variable does not have the value of 2.
- If variable's value is 2, endResult is set to the value of 4.
Note that the else statement -part can be left out if not needed.
Example:
if variable != 2 then endResult = 3 end
- This script only sets the value of 3 to endResult if variable does not have a value of 2, and doesn't do anything else.
Nesting if statements
It is possible to place if-conditionals inside the true/false statement blocks to achieve further branching of execution.
Example:
if variable == 0 then endResult = 1 else if variable == 1 then endResult = 2 end end
- This script sets endResult to 1 if variable equals 0.
- If variable doesn't equal 0, but it equals 1, endResult is set to 2.
Example:
if variable == 0 then if endResult == 1 then endResult = 2 end else endResult = 1 end
- This script sets endResult to 2 if variable has a value of 0, and endResult equals to 1.
- Otherwise it sets endResult to 1.
Note that it may be easier to plan and debug the script flow by formatting the script containing nested if-statements to a neater indented form.
Note: writing the script like this won't work on the chip, but doing this can still be useful when debugging scripts.
This is the second nested example formatted:
if variable == 0 then if otherVariable == 1 then otherVariable = 2 end else otherVariable = 1 end
Comments
Comments are useful when writing code that is used by a lot of programmers.
Note that comments also use up space from the pre-determined 70 character line limit and are not excluded from it.
Commenting is used with the following syntax:
- // text
- Text can be any single-line set of characters.
// This is a comment. It will explain how other lines of script work.
- An example of a possible comment syntax
Errors
There are two types of errors that can happen with the programming language.
- Syntax errors
- Runtime errors
- Syntax errors come from invalid and unparseable script and will result in the whole line not being executed.
- Runtime errors are only catchable while the script is being executed. They result in the execution of the line being interrupted, but any effects until the error will remain.
Known Bugs/Unintended Behavior
This is a list of known problems regarding yolol:
- variablenames including keywords like "if" in them will parse with the keyword in mind, resulting in a syntax error. Example: :life would be parsed as :l if e