Operators: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
 
mNo edit summary
Line 1: Line 1:
{{Stub}}
{{Stub}}


operators in arma
Now you meet operators and expressions - foundation-stones of every scripting language.
 
==Expressions==
 
Every expression is created from operands and operators. Operators call interpreter what it should do with operands. For example: AKMagazines * AmmoPerMagazine says: "multiple value in variable AKMagazines with value in variable AmmoPerMagazine". We evaluate expressions for obtain outcomes. If you want to store it, you must evaluate statement. For example: AllAKAmmo = AKMagazines * AmmoPerMagazine. It's order to interpreter to multiple value in variable AKMagazines with value in variable AmmoPerMagazine and prouuct store in variable AllAKAmmo (if there is any value, it will be rewritten). You need to know that expressions are evaluated from left side to right side, in statements is evaluated right expression first and outcome is stored in variable in left side. Another typical statement is VictorSide = [[side]] Victor or CarDamage = [[damage]] car.
 
===Evaluating for outcome or side effects===
 
When interpreter evaluates expression, gives you its outcome. Im most of cases it gives to you nothing, but it change something in game. (
PrivateHonka [[setDamage]] 1
increase global IQ of all army solders (kill him) ''';-)''' ).
 
===Operators===
 
Operators in <abbr title="Armed Assault Scripting Language; it isn't offical">ArmA SL</abbr> are implemented as commands (as everything). More important that previous information is that outcome of expression with arithmetic operators is number, when logical operators are used, its logical value (true or false (it's also commands which returns logical values. In other scripting languages (Python, etc.) is this value part of interpreter. (it's only small different, if you learn ArmA SL principles, you will be able to learn any other language (Python) easily). There you can see Arma SL has commands for everything.), it's data type is bool).
 
*Arithmetical operators
** [[a_plus_b|+]] // This operator can contact two strings too.
** [[a_-_b|-]]
** [[a_/_b|/]]
** [[a * b|*]]
** [[a % b|%]]
*Logical operators
** [[a_==_b|==]] // if operands on left and right side are the same, outcome is true
** [[a_!=_b|!=]] // it they are not the same, true
** [[! a|!]] //  it have one operand on left side. Outcome is operands negated value
** [[a less b|<]]
** [[a greater b|>]]
** [[a greater= b|>=]]
** [[a less= b|=<]]
 
 
==Changing variable type==
 
This operation is there limited, you can only retype to string with help of [[format]] command. Its primary function is similar to printf command in C - it replace %1, %2, %3... if occur in string given as 0. element of given array with outcome of expressions in first (%1), second(%2)... array elements - there is one different: it returns created array, not print it.
 
text = [[format]] ["Player side: %1 - Human players on that side: %2", [[side]] [[player]], [[playersNumber]] [[side]] [[player]]]
 
Now we have string about situation in game. If you are confused you don't see expression in our example, know that 'value of expression where is only variable or number without operators is the same as variable or number value, howgh'.
 


[[Category:ArmA: Scripting|Operators]]
[[Category:ArmA: Scripting|Operators]]

Revision as of 14:23, 19 December 2006

Template:Stub

Now you meet operators and expressions - foundation-stones of every scripting language.

Expressions

Every expression is created from operands and operators. Operators call interpreter what it should do with operands. For example: AKMagazines * AmmoPerMagazine says: "multiple value in variable AKMagazines with value in variable AmmoPerMagazine". We evaluate expressions for obtain outcomes. If you want to store it, you must evaluate statement. For example: AllAKAmmo = AKMagazines * AmmoPerMagazine. It's order to interpreter to multiple value in variable AKMagazines with value in variable AmmoPerMagazine and prouuct store in variable AllAKAmmo (if there is any value, it will be rewritten). You need to know that expressions are evaluated from left side to right side, in statements is evaluated right expression first and outcome is stored in variable in left side. Another typical statement is VictorSide = side Victor or CarDamage = damage car.

Evaluating for outcome or side effects

When interpreter evaluates expression, gives you its outcome. Im most of cases it gives to you nothing, but it change something in game. (

PrivateHonka setDamage 1

increase global IQ of all army solders (kill him) ;-) ).

Operators

Operators in ArmA SL are implemented as commands (as everything). More important that previous information is that outcome of expression with arithmetic operators is number, when logical operators are used, its logical value (true or false (it's also commands which returns logical values. In other scripting languages (Python, etc.) is this value part of interpreter. (it's only small different, if you learn ArmA SL principles, you will be able to learn any other language (Python) easily). There you can see Arma SL has commands for everything.), it's data type is bool).

  • Arithmetical operators
    • + // This operator can contact two strings too.
    • -
    • /
    • *
    • %
  • Logical operators
    • == // if operands on left and right side are the same, outcome is true
    • != // it they are not the same, true
    • ! // it have one operand on left side. Outcome is operands negated value
    • <
    • >
    • >=
    • =<


Changing variable type

This operation is there limited, you can only retype to string with help of format command. Its primary function is similar to printf command in C - it replace %1, %2, %3... if occur in string given as 0. element of given array with outcome of expressions in first (%1), second(%2)... array elements - there is one different: it returns created array, not print it.

text = format ["Player side: %1 - Human players on that side: %2", side player, playersNumber side player]

Now we have string about situation in game. If you are confused you don't see expression in our example, know that 'value of expression where is only variable or number without operators is the same as variable or number value, howgh'.