Difference between revisions of "LSL Constants vs Globals"
Jump to navigation
Jump to search
(Without explicit typecasts, the demo code doesn't compile...) |
Siann Beck (talk | contribs) m (Copy editing) |
||
Line 1: | Line 1: | ||
There are some advantages in using global variables over the string and key constants | There are some advantages in using global variables over the string and key constants; it's faster and uses less bytecode when it is longer than 3 characters and is used more than twice, but it uses more bytecode when it is shorter than 3 characters or is used once. This is easily demonstrated by running the scripts in Figure 1. | ||
===Pros=== | ===Pros=== | ||
* Faster | * Faster | ||
* Uses less bytecode when it is longer | * Uses less bytecode when it is longer than 3 characters and it used more than twice. | ||
===Cons=== | ===Cons=== | ||
* User can accidentally change the value. | * User can accidentally change the value. | ||
* Uses more bytecode when it is shorter | * Uses more bytecode when it is shorter than 3 characters or it used once. | ||
Revision as of 19:41, 21 November 2008
There are some advantages in using global variables over the string and key constants; it's faster and uses less bytecode when it is longer than 3 characters and is used more than twice, but it uses more bytecode when it is shorter than 3 characters or is used once. This is easily demonstrated by running the scripts in Figure 1.
Pros
- Faster
- Uses less bytecode when it is longer than 3 characters and it used more than twice.
Cons
- User can accidentally change the value.
- Uses more bytecode when it is shorter than 3 characters or it used once.
Constant | Global |
---|---|
<lsl> dead(){ key a = NULL_KEY; key b = NULL_KEY; key c = NULL_KEY; key d = NULL_KEY; } default { state_entry() { llOwnerSay((string) llGetFreeMemory()); } }</lsl> |
<lsl>key null_key = NULL_KEY; dead(){ key a = null_key; key b = null_key; key c = null_key; key d = null_key; } default { state_entry() { llOwnerSay((string) llGetFreeMemory()); } }</lsl> |