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.Set

Previous Top Next


SPR Script Language

 

ASA.Set

Adds or updates a key-value pair in an associative array.

 

Intention

 

The ASA.Set command lets you add a new key-value pair to an associative array in SPR or update an existing one. You give it the array handle (like $$TRE), a key (like $$KEY or "Name"), and a value (like $$VAL or "Alice"), and it stores them together. If the key already exists, it overwrites the old value with the new one. This is your main tool for building or editing your array’s data.

 

Imagine a phonebook array—use ASA.Set to add "Alice" → "123-4567", then later change it to "456-7890". Or in a robot script, set "Speed" → "3.14", then update it to "2.5". It’s quick and flexible, letting you fill or tweak your array as needed, whether you’re adding new entries or fixing old ones.

 

Illustration

✏️ Add or Edit: In an array with handle $$TRE, ASA.Set puts "Name" → "Alice" or updates it to "Bob".
🔄 Flexible: New keys get added, old ones get refreshed—your array grows or changes as you go!

 

Syntax

 

ASA.Set|$$TRE|$$KEY|$$VAL

 

Parameter Explanation

 

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

This is the handle of the array you’re updating. 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 setting. It can be a variable (like $$KEY) or a string (like "Name"). This is the “name” part of the pair SPR will store or update.

 

P3 - $$VAL - (Variable or Value)

This is the value you’re pairing with the key. It can be a variable (like $$VAL) or a literal value (like "Alice", "50", or "3.14"). SPR stores this—must match the array’s datatype from ASA.New (String, Quad, or Extended).

 

Examples

 

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

' ASA.Set - Sample 1: Set and Update in String Array

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

ASA.New|$$TRE|s

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

ASA.Set|$$TRE|Alice|456-7890

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

MBX.Alice’s updated number is $$VAL (should be 456-7890)

MBX.Ready

'

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

' ASA.Set - Sample 2: Set Values 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.Set - Sample 3: Set and Update in Extended FP Array

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

ASA.New|$$TRE|f

ASA.Set|$$TRE|Speed|3.14

ASA.Set|$$TRE|Speed|2.5

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

PRT.Updated Speed is $$VAL (should be 2.5)

MBX.Ready

'

 

Remarks

 

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

- $$VAL must match the array’s datatype (String, Quad, Extended) or it might fail silently.

- Overwrites existing keys—no way to check if it’s an add or update without ASA.Get first.

- No result returned—use ASA.Get to confirm the value was set.

 

Limitations

 

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

- If $$TRE isn’t valid, it might fail quietly—no error feedback.

- Can’t set multiple pairs at once—use repeated ASA.Set calls.

 

See also:

 

ASA.New

ASA.Get

ASA.Del

ASA.Validate