ASA. - Associative Array Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > ASA. - Associative Array > Assoc. Array Operation >

ASA. - Associative Array Operations

ASA.Get

Previous Top Next


SPR Script Language

 

ASA.Get

Retrieves the value associated with a specific key in an associative array.

 

Intention

 

The ASA.Get command fetches the value tied to a specific key in an associative array in SPR. You give it the array handle (like $$TRE) and the key (like $$KEY or "Name"), and it puts the value—like "Alice" or "3.14"—into $$VAL. This is your direct way to look up data by key, without needing to navigate nodes like with ASA.GetVal. It’s the go-to for quick lookups in your array.

 

Picture a phonebook array—use ASA.Get with "Alice" to get "123-4567" instantly. Or in a robot script with "Speed" → "3.14", it pulls out "3.14" without searching. It’s fast and straightforward, ideal for grabbing specific values when you know the key, like checking a setting or fetching a contact’s number.

 

Illustration

🔍 Quick Lookup: In an array with handle $$TRE, ASA.Get finds "Name" → "Alice" and gives you "Alice".
📋 Result: $$VAL holds the value for that key, ready to use!

 

Syntax

 

ASA.Get|$$TRE|$$KEY[|$$VAL]

 

Parameter Explanation

 

P1 - $$TRE - (Variable, 5 characters max)

This is the handle of the array you’re querying. It’s a 5-character variable (like $$TRE or $$ARR) from ASA.New. The command uses this to find the array.

 

P2 - $$KEY - (Variable or String)

This is the key you’re looking up. It can be a variable (like $$KEY) or a string (like "Name"). SPR finds this key in the array and gets its value.

 

P3 - $$VAL - (Optional, Variable, 5 characters max)

This is where the value goes. It’s an optional 5-character variable (like $$VAL). SPR puts the value here—could be a string (e.g., "Alice"), integer (e.g., "50"), or float (e.g., "3.14")—depending on the array’s datatype. If the key isn’t found, it might give a default (like 0 or empty). Skip this if you don’t need the value saved.

 

Examples

 

'***********************************

' ASA.Get - Sample 1: Get Value by Key in String Array

'***********************************

ASA.New|$$TRE|s

ASA.Set|$$TRE|Alice|123-4567

ASA.Set|$$TRE|Bob|987-6543

ASA.Get|$$TRE|Alice|$$VAL

MBX.Alice’s number is $$VAL (should be 123-4567)

MBX.Ready

'

'***********************************

' ASA.Get - Sample 2: Get Value by Key in Quad Array

'***********************************

ASA.New|$$TRE|i

ASA.Set|$$TRE|Red|50

ASA.Set|$$TRE|Blue|75

ASA.Get|$$TRE|Blue|$$VAL

PRT.Blue count is $$VAL (should be 75)

MBX.Ready

'

'***********************************

' ASA.Get - Sample 3: Get Value by Key in Extended FP Array

'***********************************

ASA.New|$$TRE|f

ASA.Set|$$TRE|Temp|23.5

ASA.Set|$$TRE|Speed|3.14

ASA.Get|$$TRE|Speed|$$VAL

PRT.Speed value is $$VAL (should be 3.14)

MBX.Ready

'

 

Remarks

 

- $$TRE must be valid—use ASA.Validate if unsure.

- If $$KEY isn’t in the array, $$VAL might get a default (e.g., 0 or empty string).

- It’s fast and doesn’t change the array—just reads the value.

- The value type matches the array’s datatype (String, Quad, Extended) set by ASA.New.

 

Limitations

 

- $$TRE must be 5 characters—wrong lengths might cause errors.

- If $$TRE or $$KEY isn’t valid, $$VAL might get unpredictable results—no error warning.

- Only gets the value—use node-based commands for navigation.

 

See also:

 

ASA.New

ASA.Set

ASA.GetVal

ASA.Validate