YENGconstant

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Line number clarification)
 
(6 intermediate revisions by 2 users not shown)
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.<br>
+
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
+
 
 +
Make sure to add yoptions; to the second line of the script, usually line number 1 starting from 0.
 +
 
 +
Its type will be guessed from the types at right side expression, and can be confusing
  
 
  constant endlimit = 0.1 // will be a like float 0.1
 
  constant endlimit = 0.1 // will be a like float 0.1
Line 9: Line 12:
 
  constant badidea = "2" + 3 // will be like string "23"
 
  constant badidea = "2" + 3 // will be like string "23"
  
−
This last example illustrates that mixed types, specially when one is a string, can be confusing, and should be avoid<br>
+
Other operations supported
−
since will make harder to understand a script, the opposite of its purpose.
+
−
other operations supported
+
 
  & | ^ ~ for integer types
 
  & | ^ ~ for integer types
 
  - * / % for integer or float types
 
  - * / % for integer or float types
−
+
 
−
on expressions better use () to force and make clear the desired evaluation order
+
On expressions better use () to force and make clear the desired evaluation order
 
  constant ar = 2 + (2 & 1); //will be 2
 
  constant ar = 2 + (2 & 1); //will be 2
 
  constant ar = 2 + 2 & 1; //will be 0, ie will do (2 + 2) & 1 since + and & have same evaluation priority.
 
  constant ar = 2 + 2 & 1; //will be 0, ie will do (2 + 2) & 1 since + and & have same evaluation priority.
  
−
possible the use of any operation should just be avoid.<br>
+
Simple normal use will be to define a simple constant at top of program, easy to change later.
−
better to only use to define a simple constant at top of program, easy to change later.
+
  
 
  constant textureID = "0d3b69fe-1b6e-40f3-8e5f-933814df3b7b";
 
  constant textureID = "0d3b69fe-1b6e-40f3-8e5f-933814df3b7b";
 +
 +
Saving the memory of a global variable.
 +
 +
[[Category:Scripts]]

Latest revision as of 15:04, 16 March 2021

constant allows to define a constant value that is evaluated and all its occurrences in code are replaced by that value at compile time.

Make sure to add yoptions; to the second line of the script, usually line number 1 starting from 0.

Its type will be guessed from the types at right side expression, and can be confusing

constant endlimit = 0.1 // will be a like float 0.1
constant start = 1 // will be a like integer 1
constant idea = 2 + 3 // will be like integer 5
constant betteridea = idea + 3 // will be like integer 8
constant otheridea = 2 + 3.0 // will be like float 5.0
constant badidea = "2" + 3 // will be like string "23"

Other operations supported

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

On expressions better use () to force and make clear the desired evaluation order

constant ar = 2 + (2 & 1); //will be 2
constant ar = 2 + 2 & 1; //will be 0, ie will do (2 + 2) & 1 since + and & have same evaluation priority.

Simple normal use will be to define a simple constant at top of program, easy to change later.

constant textureID = "0d3b69fe-1b6e-40f3-8e5f-933814df3b7b";

Saving the memory of a global variable.

Personal tools
General
About This Wiki