YENGconstant

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Created page with "constant allows to define a constant value that is evaluated and all its occurrences in code are replaced by that value at compile time. its type is by the types are right sid...")
 
Line 1: Line 1:
constant allows to define a constant value that is evaluated and all its occurrences in code are replaced by that value at compile time.
+
constant allows to define a constant value that is evaluated and all its occurrences in code are replaced by that value at compile time.<br>
 
its type is by the types are right side expression, and very confusing
 
its type is by the types are right side expression, and very confusing
  

Revision as of 23:20, 19 September 2020

constant allows to define a constant value that is evaluated and all its occurrences in code are replaced by that value at compile time.
its type is by the types are right side expression, and very confusing

constant endlimit = 0.1 // will be a float
constant start = 1 // will be a integer
constant idea = 2 + 3 // will be integer 5
constant idea = 2 + 3.0 // will be string 5.0 since it is at compile time will mean integer 5
constant badidea = "2" + 3 // will be string "23"

This last example illustrates that mixed types, specially when one is a string, can be confusing, and should be avoid, since will make harder to understand a script, the opposite of its purpose. other operations supported

& | ^ ~ for integer types
- * / % for integer or float types

note that evaluation precedent is not the best, the use of () is a must

constant ar = 2 + (2 & 1); //will be 2
constant ar = 2 + 2 & 1; //will be 0, ie code did (2 + 2) & 1
possible the use of any operation should just be avoid.
still useful to define something present in several places in code and we may want to change later.
Personal tools
General
About This Wiki