Sb forum speech.png DiscordLink.png FacebookLink.png RedditLink.png SteamLink.png TwitterLink.png YoutubeLink.png

Difference between revisions of "YOLOL"

From Starbase wiki
Jump to navigation Jump to search
Line 236: Line 236:
Example:<br>
Example:<br>
  '''if''' variable == 0 '''then''' endResult = 1 '''else''' '''if''' variable == 1 '''then''' endResult = 2 '''end end'''  
  '''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.
* 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.
* If '''variable''' doesn't equal 0, but it equals 1, '''endResult''' is set to 2.


  '''if''' variable == 0 '''then''' '''if''' endResult == 1 '''then''' endResult = 2 '''end''' '''else''' endResult = 1 '''end'''
  '''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.
* This script sets '''endResult''' to 2 if '''variable''' has a value of 0, and '''endResult''' equals to 1.
* Otherwise it sets endResult to 1.
* Otherwise it sets '''endResult''' to 1.


  '''if''' variable == 0 '''then''' '''if''' otherVariable == 1 '''then''' '''if''' thirdVariable == 2 '''then''' fourthVariable = 3 '''end end end'''  
  '''if''' variable == 0 '''then''' '''if''' otherVariable == 1 '''then''' '''if''' thirdVariable == 2 '''then''' fourthVariable = 3 '''end end end'''  

Revision as of 12:18, 18 March 2019

Summary

YOLOL is the programming language used to control and manage electric devices.
The code is written on lines in chips which are then inserted to chip sockets, that read and relay their messages.
With YOLOL, it's possible to program and control almost any device within the known universe.

Basic information

How it works?

YOLOL code is written to and executed from YOLOL chips, and can be used to monitor and control electrical devices connected to the data network the chip is connected to.
Lines of code are executed in sequence from top to bottom, repeating the cycle of the chip after the last line has been executed, unless the script includes instructions for specific line changes, or stopping code completely.

To put it simply:

  1. Code execution starts from line 1
  2. After reading line 1, it proceeds to the next line based on the chip time interval
  3. The process is repeated
  4. If there are no special cases, the chip will begin executing line 1 again after the last line has been executed

Related pages

Command references

Case insensitive

YOLOL is fully case insensitive.
This means that the following two example scripts function identically to each other:

if ButtonState == 1 then DoorState = 1 end
IF buttonstate == 1 THEN doorstate = 1 END

The characters can however be written in either lowercase or uppercase letters.
This way it's possible to have your YOLOL code look a bit more organized.

Variables

The variables in YOLOL are weakly typed (don't enforce type validity), and support two data types: fixed-point decimals(up to 0.001 precision) and strings.
To put it simply, the variables can either be introduced as strings or numbers at any point, ignoring the earlier variable type.
Each variable is always of a single type, though it will be implicitly converted when required.
The default value of an uninitialized variable is 0, and nil values are not supported.
True/False are numerical values of non-0 and 0.

Assigning a value to a variable always converts the variable to the value's type.

Example:

ultimateAutopilot= 128.6432

This results in the variable ultimateAutopilot containing a numeric value of 128.6432

ultimateAutopilot= "Error prone"

This results in the variable ultimateAutopilot to be a string variable "Error prone", and numeric value of 128.6432 is removed.

Decimals

Numeric values in YOLOL are 64-bit integers.
The variables hold decimal numbers up to four decimal accuracy

pieVariable= 3.1415

The above script assigns a numeric value of 3.1415 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 assigns a numeric value of 0.5772 to the variable notPieVariable.

Strings

To specify a string literal in YOLOL, the desired string value must be surrounded with double quotation marks.

stringStorage= "saltberia" 

This script assigns the string value of "saltberia" to the variable stringStorage.

Device fields / External variables

External variables and device fields can be used within the YOLOL programming with the following syntax:

  • :variableName
    • variableName being the configured device field id.

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.
The prefix ':' is used to tell the script that we are trying to access an external variable, instead of using one that may or may not be declared/used in the script.

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.

Operators and commands

Note that the available operators may be limited by the type of YOLOL chip.
Basic chips have a limited selection of functions while more advanced ones can perform more complex operations natively.

Basic arithmetic and assignment operators

Operation Numeric operation String operation
A + B Addition String A is appended by String B.
A - B Subtraction The last appearance of String B in String A is removed from String A.
A * B Multiplication Runtime error. The rest of the line is skipped.
A / B Division Runtime error. The rest of the line is skipped.
A ++ PostIncrement (A=A+1) Appends a space to String A. Evaluates to the original value.
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.
++ A PreIncrement (A=A+1) Appends a space to String A. Evaluates to the modified value.
-- 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.
A = B Assignment (Variable A is set to the value of variable B) Assignment
A += B Addition-assignment (A=A+B) A is assigned the value of string-operation A+B
A -= B Subtraction-assignment (A=A-B) A is assigned the value of string-operation A-B
A *= B Multiplication-assignment (A=A*B) Runtime error for string variables. The rest of the line is skipped.
A /= B Division-assignment (A=A/B) Runtime error for string variables. The rest of the line is skipped.
A %= B Modulo-assignment (A=A%B) Runtime error for string variables. The rest of the line is skipped.
A ^ B Exponentiation Runtime error for string variables. The rest of the line is skipped.
A % B Modulo Runtime error for string variables. The rest of the line is skipped.
ABS A Modulus (absol value) (A=A if A>=0, else A=-A) Runtime error for string variables. The rest of the line is skipped.
A! Factorial Runtime error for string variables. The rest of the line is skipped.
SQRT A Square root of A Runtime error for string variables. The rest of the line is skipped.
SIN A Sine of A (degrees) Runtime error for string variables. The rest of the line is skipped.
COS A Cosine of A (degrees) Runtime error for string variables. The rest of the line is skipped.
TAN A Tangent of A (degrees) Runtime error for string variables. The rest of the line is skipped.
ARCSIN A Inverse sine of A (degrees) Runtime error for string variables. The rest of the line is skipped.
ARCCOS A Inverse cosine of A (degrees) Runtime error for string variables. The rest of the line is skipped.
ARCTAN A Inverse tangent of A (degrees) Runtime error for string variables. The rest of the line is skipped.

Logical operators

Logical operators are checks, whether or not statement is true or false.
All logical operations return either "0 for False" or "1 for True"

Operation Numeric operation String operation
A < B Less than returns 1 if String A is first in alphabetical order, returns 0 if not.
A > B Greater than returns 0 if String A is first in alphabetical order, returns 1 if not.
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.
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.
A ~= B Not equal to returns 1 if String A is not equal to String B, 0 if it is.
A == B Equal to returns 1 if String A is equal to String B, 0 if not.

You can also use the not, and and or keywords to set up more complicated conditions than simple variable value checks.

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 the command will take the script execution.
    • Any remaining script that is on the same line after the goto-command will not be executed.
    • Multiple goto commands can be added on the same line using conditionals, as False goto commands are skipped.
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.

If-else conditional

If-else statements are used to branch out the YOLOL 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.

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 ifs

It's 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.
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.
if variable == 0 then if otherVariable == 1 then if thirdVariable == 2 then fourthVariable = 3 end end end 

This script sets fourthVariable to 3 if variable equals to 0, otherVariable has a value of 1, and thirdVariable has a value of 2.


Note that it may be easier to plan and debug the script flow by formatting the yolol-script containing nested ifs to a neater indented form. Also note that writing the script like this won't work in-game, 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 with larger amounts of programmers.
Note that comments also use up 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 to you how other lines of script work.

Errors

Cookies help us deliver our services. By using our services, you agree to our use of cookies.