|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > ASA. - Associative Array > Assoc. Array Operation > ASA. - Associative Array Operations |
SPR Script Language
ASA.Last
Returns the handle to the last node in an associative array.
Intention
The ASA.Last command takes you to the end of an associative array in SPR. You give it the array’s handle (like $$TRE), and it finds the very last key-value pair—called a node—and gives you a node handle in $$NODE. This handle lets you look at that last pair’s key and value using ASA.GetKey and ASA.GetVal. It’s your starting point for working backward through the array with ASA.Prev, or just to check the final entry.
Picture a phonebook array—ASA.Last jumps to the last name, maybe "Zoe" → "555-1234". You can see that entry or step back to earlier ones. Or in a robot script with settings like "Speed" → "3.14", it takes you to the last one added or sorted. It’s a quick way to peek at the end of your data, great for reviewing the latest entry or starting a reverse loop.
Illustration
🏁 End Here: In an array with handle $$TRE, ASA.Last points you to the last pair, like "Age" → "25".
🔗 Node Handle: $$NODE gets a number to access that final entry!
Syntax
ASA.Last|$$TRE[|$$NODE]
Parameter Explanation
P1 - $$TRE - (Variable, 5 characters max)
This is the handle of the array you’re checking. It’s a 5-character variable (like $$TRE or $$ARR) from ASA.New. The command uses this to find the last node.
P2 - $$NODE - (Optional, Variable, 5 characters max)
This is where the node handle goes. It’s an optional 5-character variable (like $$NODE). SPR puts a number here—a non-zero value if there’s a last node, or zero if the array is empty. Use this with ASA.GetKey or ASA.GetVal to see the details.
Examples
'***********************************
' ASA.Last - Sample 1: Get Last Node in a String Array
'***********************************
ASA.New|$$TRE|s
ASA.Set|$$TRE|Alice|123-4567
ASA.Set|$$TRE|Bob|987-6543
ASA.Last|$$TRE|$$NOD
ASA.GetKey|$$NOD|$$KEY
MBX.Last key is $$KEY (might be Bob)
MBX.Ready
'
'***********************************
' ASA.Last - Sample 2: Check Last in a Quad Array
'***********************************
ASA.New|$$TRE|i
ASA.Set|$$TRE|Red|50
ASA.Set|$$TRE|Blue|75
ASA.Last|$$TRE|$$NOD
ASA.GetVal|$$NOD|$$VAL
PRT.Last value is $$VAL (might be 75)
MBX.Ready
'
'***********************************
' ASA.Last - Sample 3: Last in an Empty Extended FP Array
'***********************************
ASA.New|$$TRE|f
ASA.Last|$$TRE|$$NOD
PRT.Last node handle in empty array: $$NOD (should be 0)
MBX.Ready
'
Remarks
- $$TRE must be valid—check with ASA.Validate first.
- If the array is empty, $$NODE gets 0—no last node to find!
- The “last” node depends on SPR’s internal sorting—often alphabetical by key, but it’s not guaranteed.
- Pair with ASA.Prev to loop backward, or use ASA.First to see the other end.
Limitations
- $$TRE must be 5 characters—wrong lengths might cause issues.
- If $$TRE isn’t valid, $$NODE might get nonsense—no error warning.
- Only gives the node handle—use other commands to see the key or value.
See also:
• ASA.New
• ASA.Prev