hwarren

E2 Syntax

Jan 23rd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.25 KB | None | 0 0
  1. @name E2 Syntax
  2. @persist Sum
  3. #####Variables##################################################
  4. ####Basics##################################################
  5.  
  6. #[  Variables are defined with a single equal sign (=) ]#
  7.  
  8. Var_1 = 1
  9.  
  10. #[  Variables are thrown away at the end of the tick
  11.     To carry a variable across ticks, we put it in @persist, as follows
  12.    
  13. @persist Var
  14.  
  15.     Note that you don't need to include a variable's type if the variable is a number
  16.     However, if you set the variable to be anything else, you must specify its type ]#
  17.    
  18. Var_2 = entity()
  19.  
  20. #[  Now you must persist Var_2 with its type specified, as follows
  21.  
  22. @persist Var_2:entity
  23.  
  24.     When specifying a type, it is in all lower-case, and should be an orange color
  25.     Variable types include:
  26.     - entity
  27.     - string
  28.     - array
  29.     - ranger
  30.     - vector
  31.     - angle
  32.    
  33.     When persisting multiple variables, they are separated by a space
  34.    
  35. @persist Var_1 Var_2:entity
  36.  
  37.     And if they are of the same type, you can enclose them in brackets and specify the type at the end of the brackets ]#
  38.  
  39. Var_3 = entity()
  40.  
  41. #[
  42. @persist Var_1 [Var_2 Var_3]:entity
  43.  
  44.     As Var_2 and Var_3 are both of the type entity, we can group them together
  45.    
  46. ]#
  47.  
  48.  
  49.  
  50. ####Variable Types#######################################################################################################################################################################
  51. ###Strings####
  52.  
  53. #[  Strings are basically just text (that can be used by the expression in functions)
  54.     Strings are surrounded by quotations (" and ") ]#
  55.  
  56. String = "Hello, world"
  57.  
  58. ###Entities############################################################################################################################################################################################################
  59.  
  60. #[  An entity is any 'thing' in the world
  61.     Entities are usually called via some function, like entity(), which returns the E2 chip itself ]#
  62.    
  63. Entity = entity()
  64.  
  65. ###Vectors#########################################################################################################################
  66.  
  67. #[  A vector is either a direction or position (or both)
  68.     A vector can be created with vec(x,y,z) or called via a function ]#
  69.    
  70. Vector_1 = vec(20,20,100)
  71.  
  72. Vector_2 = Entity:pos()
  73.  
  74. ###Angles#########################################################################################################################
  75.  
  76. #[  An angle specifies the orientation of an object (or just itself)
  77.     Similarly to vectors, angles can be created with ang(p,y,r) or called via a function ]#
  78.    
  79. Angle_1 = ang(90,45,0)
  80.  
  81. Angle_2 = Entity:angles()
  82.  
  83. ###Arrays#########################################################################################################################
  84.  
  85. #[  An array is basically a list of entities, vectors, strings, angles, rangers, etc.
  86.     They're extremely useful when storing a lot of data for later manipulation
  87.    Arrays can be created with array(variable 1,2,3,4,..n), or called with a function ]#
  88.    
  89. Array_1 = array(Angle_1, Angle_2, Vector_1, Vector_2)
  90.  
  91. Array_2 = players()
  92.  
  93.  
  94.  
  95. #####Functions##################################################
  96.  
  97. #[  A function is basically anything that actively does something
  98.    Functions always start with a lower-case letter, but may have upper-case letters to separate words
  99.    Variables can make functions easier to read, as well as create less lag if used frequently ]#
  100.  
  101. findByName(String)
  102.  
  103. #[  Functions are always immediately succeeded by open parenthasese (()
  104.    And always ended by closed parenthases ())
  105.    
  106.    Every ( must have a ) to close it ]#
  107.    
  108. findByName(Entity:owner():name())
  109.  
  110. #[  Parenthasese are also used in order of operations
  111.    Functions can be called within functions, depending on whether its output is valid ]#
  112. #####Statements##################################################
  113.  
  114. #[  If statements are checked once every tick
  115.    If their condition is true, then it runs its statement:
  116.    
  117. if(condition) { statement }
  118.  
  119.    An if-else statement is just an if statement thats extended to run a code if its condition is false
  120.    
  121. if(condition) { statementtrue } else { statementfalse }
  122.  
  123.    Similarly, there are if-elseif statements, that only run if the previous if check failed and its own conditions are true
  124.    And can be build onto itself
  125.    
  126. if(condition) {
  127.    statement
  128.    
  129.    } elseif(condition) {
  130.        statement
  131.        
  132.    } elseif(condition) {
  133.        statement
  134.        
  135.    } else {
  136.        statement
  137.    }
  138.  
  139.  
  140. ####Loops####
  141.  
  142. #[  For loops are incredibly useful with arrays
  143.    In the format for(Var = A, B, C) { statement }:
  144.    Substitute for Var every C(-st/nd/rd/th) number from A to B
  145.    
  146.    Generally I is used in place of Var, and C is commonly left out, as it isn't always needed ]#
  147.  
  148. for(I = 1, 10) {
  149.     Sum = Sum + I
  150.    
  151. }
  152.  
  153. #[  Note that when defining a variable Var with itself, you must put it in @persist
  154.  
  155.     In this example, Sum would equal 55 (1+2+3+4+5+6+7+8+9+10) ]#
  156.    
  157.  
  158. #[  While loops loop infinitely per tick, at least until their condition is false
  159.     You would be better off with a for loop 99% of the time
  160.    
  161. while(condition) { statement }
  162.  
  163. ]#
Advertisement
Add Comment
Please, Sign In to add comment