ASA. - Associative Array Operations

<< Click to Display Table of Contents >>

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

ASA. - Associative Array Operations

ASA.Clear

Previous Top Next


SPR Script Language

 

ASA.Clear

Removes all key-value pairs from an associative array, keeping the array intact.

 

Intention

 

The ASA.Clear command empties out an associative array in SPR. It takes the handle (like $$TRE) and wipes away all the keys and values inside, but keeps the array itself alive. This is different from ASA.End, which deletes the whole array—here, $$TRE stays valid, and you can add new data with ASA.Set right after. It’s handy when you want to reuse an array without starting over from scratch with ASA.New.

 

Say you’ve got a phonebook array with names and numbers, and you want to clear it out for a new list. ASA.Clear erases all the entries (like "Alice" → "123-4567"), but the phonebook itself sticks around, ready for fresh names. Or maybe your robot script tracks sensor data (like "Temp" → "23.5")—use this to reset the data without losing the array setup. It’s a quick way to start over with an existing array, keeping your script neat and efficient.

 

Illustration

🧹 Empty It Out: An array with handle $$TRE loses all pairs (e.g., "Name" → "Alice"), but $$TRE still works.
♻️ Ready to Reuse: After ASA.Clear, add new data with ASA.Set—no need to remake the array!

 

Syntax

 

ASA.Clear|$$TRE

 

Parameter Explanation

 

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

This is the handle of the array you want to clear. It’s a 5-character variable (like $$TRE or $$ARR) from ASA.New. After ASA.Clear runs, all data is gone, but $$TRE stays valid for new entries.

 

Examples

 

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

' ASA.Clear - Sample 1: Clear a String Array

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

ASA.New|$$TRE|s

ASA.Set|$$TRE|Name|Alice

ASA.Clear|$$TRE

ASA.Get|$$TRE|Name|$$VAL

MBX.Text|After clear, Name is: $$VAL (should be empty)

MBX.Ready

'

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

' ASA.Clear - Sample 2: Clear and Reuse a Quad Array

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

ASA.New|$$TRE|i

ASA.Set|$$TRE|Count|100

ASA.Clear|$$TRE

ASA.Set|$$TRE|Count|200

ASA.Get|$$TRE|Count|$$VAL

PRT.Count after clear and reset: $$VAL (should be 200)

MBX.Ready

'

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

' ASA.Clear - Sample 3: Clear an Extended FP Array

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

ASA.New|$$TRE|f

ASA.Set|$$TRE|Speed|2.5

ASA.Clear|$$TRE

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

PRT.Speed after clear: $$VAL (should be 0 or empty)

ASA.Set|$$TRE|Speed|3.7

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

PRT.New Speed value: $$VAL (should be 3.7)

MBX.Ready

'

 

Remarks

 

- $$TRE must be a valid handle from ASA.New—check with ASA.Validate first if you’re not sure.

- After ASA.Clear, the array is empty but reusable—unlike ASA.End, which kills it completely.

- Works the same for all datatypes (String, Quad, Extended) set by ASA.New—everything gets wiped.

- No result is returned, so you can’t tell if it failed unless you check the array afterward with ASA.Get.

 

Limitations

 

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

- If $$TRE isn’t valid, the command might fail silently—no way to know without testing.

- You can’t clear just some keys—it’s all or nothing.

 

See also:

 

ASA.New

ASA.End

ASA.Set

ASA.Get