|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > Array -Commands > !FP-Arrays > Array - Commands |
MiniRobotLanguage (MRL)
ARR.Set FP Array
Set Array Element to Floating-Point Value

Output of the sample script below, showing a floating-point array set with multiple values.
Intention
The ARR.Set FP Array command sets the value of a specific element in a specified floating-point array (P1) at the given index (P2) to a floating-point value (P3). This is useful for populating arrays with numerical data, particularly when high precision is required. The command supports setting multiple elements at once by providing a comma-separated list of values in P3, starting from the specified index.
Values are stored as strings internally, consistent with MRL’s array storage mechanism, and are treated as extended-precision floating-point numbers (10 bytes, 18 digits of precision). The array is automatically resized if the specified index is out of range, ensuring flexibility in array manipulation.
•Element Update: Sets the value of the element at the specified index (P2) in the specified array (P1).
•Data Types: The value (P3) should be an extended-precision floating-point number, offering 18 digits of precision and requiring 10 bytes of storage.
•Multiple Values: P3 can contain multiple comma-separated values, which are assigned to consecutive indices starting from P2.
•Auto-Dim: If the index is out of range, the array is automatically resized to accommodate the new elements.
Schematic (Floating-Point Array Setting)
Array[5]: []
Command: ARR.Set FP Array|5|0|3.14,2.718,-1.23
Result Array[5]: ["3.14", "2.718", "-1.23"]
Syntax
ARR.Set FP Array|P1|P2[|P3]
ARR.SFP|P1|P2[|P3]
Parameter Explanation
•P1 - Array Number: Specifies the array number, which can range from 0 to 32.
•P2 - Array Index: Specifies the index of the element within the array to set. If multiple values are provided in P3, this is the start index.
•P3 - Value (Optional): Specifies the floating-point value(s) to set, either as a single value or a comma-separated list. If omitted, the element is cleared (set to zero).
Speed in Ticks:

Setting multiple elements or formulas is slightly slower than setting a single element.
Examples
'***********************************
' Example 1: Set a single floating-point array element
'***********************************
ARR.Set FP Array|5|0|3.14159
ARR.Get FP Array|5|0|$$RET
MBX.$$RET
ENR.
'***********************************
' Example 2: Set multiple floating-point array elements
'***********************************
$$NUA=7
$$ELE=10.324,12,($$NUA*4/89.67),56.5,78.8,(99*4/9.762)
ARR.Set FP Array|0|0|$$ELE
ARR.Get Dim|0|$$RET
MBX.Array Dimension: $$RET
ENR.
'***********************************
' Example 3: Set element with omitted value (clear)
'***********************************
ARR.Set FP Array|3|0
ARR.Get FP Array|3|0|$$RET
MBX.$$RET
ENR.
'============================================================
' SELF-VALIDATING TEST SCRIPT for ARR.Set FP Array
' Purpose: Verify functionality with JIV. for automated checks.
' Tests setting single/multiple values, clearing elements, and invalid parameters.
'============================================================
' Initialize counters
$$PAS=0
$$FAI=0
STS.CLEAR
PRT. ===================================================
PRT. Test 1.1: Set a single floating-point value
STS.CLEAR
ARR.Clr|1
ARR.Set FP Array|1|0|3.14
ARR.Get FP Array|1|0|$$RET
$$EXP=3.14
JIV.$$RET!$$EXP|Lab_Error1
PRT. -> PASS
VIC.$$PAS
JMP.Lab_Next1
:Lab_Error1
GSB.Test
'-----------------------------------------------------------
:Lab_Next1
PRT. Test 1.2: Set multiple floating-point values
STS.CLEAR
ARR.Clr|2
ARR.Set FP Array|2|0|1.5,2.718,3.14159
ARR.Get FP Array|2|1|$$RET
$$EXP=2.718
JIV.$$RET!$$EXP|Lab_Error2
PRT. -> PASS
VIC.$$PAS
JMP.Lab_Next2
:Lab_Error2
GSB.Test
'-----------------------------------------------------------
:Lab_Next2
PRT. Test 1.3: Clear an element (omit P3)
ARR.Clr|3
ARR.Set FP Array|3|0|1.23
ARR.Set FP Array|3|0|0
ARR.Get FP Array|3|0|$$RET
$$EXP=0
JIV.$$RET!$$EXP|Lab_Error3
PRT. -> PASS
VIC.$$PAS
JMP.Lab_Next3
:Lab_Error3
GSB.Test
'-----------------------------------------------------------
:Lab_Next3
PRT. ===================================================
PRT. TEST SUMMARY
PRT. ===================================================
CAL.$$TOT=$$PAS+$$FAI
$$MSG=Total Tests: $$TOT
PRT.$$MSG
$$MSG=Passed: $$PAS
PRT.$$MSG
$$MSG=Failed: $$FAI
PRT.$$MSG
JIV.$$FAI=0|Lab_Success
$$MSG=FAILURE: $$FAI of $$TOT tests failed.
MBX.$$MSG|Test Result|16
JMP.Lab_End
:Lab_Success
MBX.SUCCESS: All tests passed!|Test Result|64
:Lab_End
ENR.
:Test
$$MSG= -> FAIL - Result: $$RET (exp: $$EXP)
PRT.$$MSG
VIC.$$FAI
RET.
Remarks
- Values are stored as strings internally, consistent with MRL’s array storage mechanism.
- The command supports mixing data types within arrays, but only floating-point values should be used with floating-point arrays to ensure compatibility with other FP-specific commands.
- Invalid indices or array numbers result in no operation.
- Non-numeric values for P3 may be stored as strings but could cause issues with subsequent floating-point operations.
Limitations
- Array numbers are limited to 0–32, consistent with other MRL array commands.
- Invalid array numbers (e.g., negative or >32) or indices result in no operation.
- The command requires at least two parameters; fewer parameters result in no operation.
- No support for multidimensional arrays; use other commands for complex array structures.
See also:
• Insert
• Swap
• Delete