Difference between revisions of "Template:LSL Function/negative index"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 54: Line 54:
   |2={{LSLP|{{{2}}}}} & {{LSLP|{{{3}}}}}
   |2={{LSLP|{{{2}}}}} & {{LSLP|{{{3}}}}}
   |3={{LSLP|{{{2}}}}}, {{LSLP|{{{3}}}}} & {{LSLP|{{{4}}}}}
   |3={{LSLP|{{{2}}}}}, {{LSLP|{{{3}}}}} & {{LSLP|{{{4}}}}}
  }}}} {{#if:{{#var:t}}| support{{#ifexpr:{{#var:ni_c}}>1||s}}| ''do{{#ifexpr:{{#var:ni_c}}>1||es}} not'' support }} {{LSLGC|Negative_Index{{#var:lang}}|negative indexes}}{{LSLC|Positive_Index_Only{{#var:lang}}}}.{{PBR}}
  }}}} {{#if:{{#var:t}}| support{{#ifexpr:{{#var:ni_c}}>1||s}}| ''do{{#ifexpr:{{#var:ni_c}}>1||es}} not'' support }} {{LSLGC|Negative_Index{{#var:lang}}|negative indexes}}.{{PBR}}
}}
}}


{{#vardefine:footer|{{#var:footer}}
{{#vardefine:footer|{{#var:footer}}
{{#if:{{#var:t}}|{{#ifeq:{{NAMESPACE}}|Template||{{#if:{{#var:self}}{{{self|}}}||{{LSLC|Negative Index{{#var:lang}}}}}}}}}}}}
{{#if:{{#var:t}}|{{#ifeq:{{NAMESPACE}}|Template||{{#if:{{#var:self}}{{{self|}}}{{#pos:{{#var:moded}}|r}}{{#pos:{{#var:moded}}|u}}||{{LSLC|Negative Index{{#var:lang}}}}}}}}|
{{#if:{{#var:self}}{{{self|}}}{{#pos:{{#var:moded}}|r}}{{#pos:{{#var:moded}}|u}}||{{LSLC|Positive_Index_Only{{#var:lang}}}}}}
}}}}


{{#vardefine:caveats|{{#var:caveats}}
{{#vardefine:caveats|{{#var:caveats}}

Revision as of 21:30, 27 September 2013

Format: {{LSL Function/negative index|boolean|p1|p2|p3}}
Exclude p1, p2, or p3 if not used.





Debugging

#var value
header_footnote

{{{2}}} & {{{3}}} support negative indexes.

spec
Index Positive Negative
First 0 -length
Last length - 1 -1

Indexes

  • Positive indexes count from the beginning, the first item being indexed as 0, the last as (length - 1).
  • Negative indexes count from the far end, the first item being indexed as -length, the last as -1.
caveats
  • If either {{{2}}} or {{{3}}} are out of bounds the script continues to execute without an error message.
  • {{{2}}} & {{{3}}} will form an exclusion range when {{{2}}} is passed {{{3}}} (Approximately: {{{2}}} > {{{3}}}).
notes

Ranges & Indexes

The easiest way to explain how ranges work is to make all indexes positive. Negative indexes are just a way of counting from the tail end instead of the beginning, all negative indexes have a corresponding equivalent positive index (assuming they are in range). Positive indexes past length (after the last index), or negative indexes past the beginning (before the first index) are valid and the effects are predictable and reliable: the entries are treated as if they were there but were removed just before output.

  • If number <= p2 then the range operated on starts at number and ends at p2. [number, p2]
  • Exclusion range: If number > p2 then the range operated on starts at 0 and goes to p2 and then starts again at number and goes to -1. [0, p2] + [number, -1]
    • If p2 is a negative index past the beginning, then the operating range would be [number, -1].
    • If p2 is a positive index past the end, then the operating range would be [0, p2].
    • If both number and p2 are out of bounds then the function would have no operating range (effectively inverting what the function is supposed to do).

See negative indexes for more information.

constants_nb
also_articles
•  Test
•  Negative Index
footer