Walid Posted May 28, 2015 Posted May 28, 2015 (edited) Hello everybody Today in this tutorial i will explain to you the arithmetic, relational, and logical operators one by one. it's easy just try to follow my tutorial step by step . Arithmetic Operators: `+´ , `-´ , `*´ , `/´ , `-´ , `^´ Relational Operators : `<´ , `>´ , `<=´ , `>=´ , `==´ , `~=´ Logical Operators: `and´, `or´, `not´ Misc Operators: `..´, `# Following table shows all the arithmetic operators supported by Lua language. Description: Operator `+´ (addition) : Adds two operands Ex: 1 + 5 = 6 `-´ (subtraction): Subtracts second operand from the first Ex: 10-30 = -20 `*´ (multiplication): Multiply both operands Ex: 5 * 3 = 15 `/´ (division): Divide numerator by de-numerator Ex: 8 / 2 = 4 `^´ (exponentiation): Exponent Operator takes the exponents Ex: 5 ^ 2 = 25 Examples: local W = 5 local M = 10 outputChatBox(W + M) -- Addition: 15 outputChatBox(W - M) -- Subtraction: -5 outputChatBox(W * M) -- Multiplication: 50 outputChatBox(W / M) -- Division: 0.5 outputChatBox(W^2) -- Exponentiation: 25 Relational operators are supplied which return the boolean values true or false. Description: Operator `==´ (equal to) : Example (5 == 6) false `~=´ (not equal to) : Example (5 ~= 6) true `<´ (less than) : Example (5 < 6 ) true `>´ (greater than) : Example (5 > 6 ) false `<=´ (less than or equal to) : Example (5 <= 6 ) true `>=´(greater than or equal to) : Example (5 >= 6 ) false Example: local W = 5 local M = 10 -- Example 1 : == Equal to if( W == M ) then outputChatBox(W.." is equal to "..M ) else outputChatBox(W.." is not equal to "..M ) end -- Example 2 : ~= Not equal to if( W ~= M ) then outputChatBox(W.." is not equal to "..M ) else outputChatBox(W.." is equal to "..M ) end -- Example 3 : < less than if ( W < M ) then outputChatBox(W.." is less than "..M ) else outputChatBox(W.." is not less than "..M ) end -- Example 4 : Greater than if ( W > M ) then outputChatBox(W.." is greater than "..M) else outputChatBox(W.." is not greater than "..M ) end -- Example 5 : <= less than or equal to if ( W <= M ) then outputChatBox(W.."is either less than or equal to "..M ) end -- Example 6 : >= greater than or equal to if ( M >= W ) outputChatBox(M.." is either greater than or equal to "..W ) end Note: These also work on strings (alphabetical order) and other types. Following table shows all the logical operators supported by Lua language Description: Operator `and´: (Called Logical AND operator) Example:(true and false) is false `or´: (Called Logical OR Operator) Example:(true or false) is true `not´: (Called Logical NOT Operator) Example: (not true) is false Also there is Miscellaneous operators supported by Lua Language include concatenation and length. Description: `..´ : Concatenates two strings. `#´ : An unary operator that return the length of the a string or a table. Examples: local W = "Hello" local M = "Everybody" -- Example 1 : Concatenates two strings. outputChatBox(W.." "..M) -- Result: Hello Everybody -- Example 2: outputChatBox(#W) -- Result: 5 Edited September 8, 2016 by Walid 2 1 Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
xXMADEXx Posted May 28, 2015 Posted May 28, 2015 Good tutorial, but you should add in the "..." operator too. The Ultimate Lua Tutorial! | MTA PHP SDK
Mr.unpredictable. Posted May 28, 2015 Posted May 28, 2015 Great Job, This topic is really very useful for people who just started scripting.
Walid Posted May 28, 2015 Author Posted May 28, 2015 Good tutorial, but you should add in the "..." operator too. Great Job, This topic is really very useful for people who just started scripting. Thx guys. Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Walid Posted May 28, 2015 Author Posted May 28, 2015 Awesome TuT, helpful like always @Walid Thx hope it helps. Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
KariiiM Posted May 28, 2015 Posted May 28, 2015 (edited) Thx hope it helps. Yep it does,i will share it with my friends some of them need to learn the LUA operators,im sure this will helps them its clear and understandable to newbies,thanks for your works. Edited April 9, 2016 by Guest
Mann56 Posted May 28, 2015 Posted May 28, 2015 Cool work dude ! Can you add the string and math functions as well? I would really be nice. "When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag" "Have confidence in yourself, no problem is impossible in life"
Walid Posted May 28, 2015 Author Posted May 28, 2015 Cool work dude !Can you add the string and math functions as well? I would really be nice. Maybe i will add an other TUT. thx. Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Mann56 Posted May 29, 2015 Posted May 29, 2015 Cool work dude !Can you add the string and math functions as well? I would really be nice. Maybe i will add an other TUT. thx. Thank you dude "When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag" "Have confidence in yourself, no problem is impossible in life"
Walid Posted May 29, 2015 Author Posted May 29, 2015 Thank you dude np. Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
xeon17 Posted May 29, 2015 Posted May 29, 2015 Good tutorial , keep it up. A unique GangWar gamemode waiting for you!Click here for more information.
Walid Posted May 29, 2015 Author Posted May 29, 2015 Good tutorial , keep it up. Thank you. Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
TAPL Posted June 6, 2015 Posted June 6, 2015 There won't be space between Hello and Everybody on example 1 result.
Walid Posted June 6, 2015 Author Posted June 6, 2015 There won't be space between Hello and Everybody on example 1 result. Yeh bro it's just an example of how to concatenates two strings. outputChatBox(W.. " "..M) -- Result: Hello Everybody. anyways thx. Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
SkatCh Posted June 13, 2015 Posted June 13, 2015 This topic is really very useful Failure is simply an opportunity to begin again more intelligently - Henry Ford
Walid Posted June 14, 2015 Author Posted June 14, 2015 This topic is really very useful thx bro Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Recommended Posts