Asked
How To Create Multidimensional Arrays
Could you please show me how to create an array with 20 names, each associated with three values (x, y, z)? Additionally, I would like to generate a chart on the desktop that displays these names and their corresponding values.
Furthermore, I need to extract the values for a specific name and use them to control servo movements.
This assistance would be greatly appreciated.
Thank you, Don
@Athena Got the start name and start index working properly but one thing that you missed in the function was the amount of iterations which was declared in a different script. Can you also make a different function that uses the start name for the first location but goes in reverse for a certain amount of iterations which are declared in a different script and made to be a global variable.
Great to hear that the start name and start index are working properly! Now, let's add the functionality to handle a specified number of iterations and create a function that iterates in reverse for a certain number of iterations.
Forward Iteration with Specified Number of Iterations
First, let's ensure that the forward iteration respects the specified number of iterations.
Reverse Iteration with Specified Number of Iterations
Next, we'll create a function that starts from the specified start name and iterates in reverse for a certain number of iterations.
Example Code
Here's the complete code for both forward and reverse iterations:
Explanation:
items
array contains names and their correspondingx
,y
,z
values.startName
andnumIterations
are retrieved from global variables.startIndex
and iterates for the specified number of iterations.reverseIteration
function starts from thestartIndex
and iterates in reverse for the specified number of iterations.Notes:
startName
andnumIterations
global variables are correctly set.d0
,d1
,d2
) as per your setup.This approach ensures that the iteration starts from the specified start name and continues for the specified number of iterations, both forward and reverse. If you have any further questions or need additional assistance, feel free to ask!
I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
@Athena Got the iterations working properly, thanks. Can you make a function that adds the location of V26 which is x, V27 which is y, V1 which is z, to the bottom of this existing array every time variable Add_To_Array turns true. I will use a switch to trigger the variable to turn true.
Sure! Let's create a function that adds a new entry to the bottom of the existing array whenever the
Add_To_Array
variable turns true. This function will read the values from the specified virtual servo ports (V26 for x, V27 for y, and V1 for z) and add them to the array.Example Code
Here's the complete code to achieve this:
Explanation:
items
array contains names and their correspondingx
,y
,z
values.startName
andnumIterations
are retrieved from global variables.forwardIteration
function starts from thestartIndex
and iterates for the specified number of iterations.reverseIteration
function starts from thestartIndex
and iterates in reverse for the specified number of iterations.Add_To_Array
variable, reads the values from the specified virtual servo ports (V26
,V27
,V1
), and adds a new entry to the array. It also generates a unique name for the new entry and resets theAdd_To_Array
variable.Add_To_Array
variable to add new entries.This approach ensures that new entries are added to the array whenever the
Add_To_Array
variable turns true. If you have any further questions or need additional assistance, feel free to ask!I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
@Athena Could not get the add to array function working. Let's backtrack - I have the define array in a different script which then saves it to a global variable. I'd like to have the Add_Locations variable start the script (Define array) which would then have Add to array function grab the 3 positions and put them on the end of the array. I want to be able see that it has added the locations to the bottom of the array.
Got it! Let's break it down step-by-step to ensure everything works as expected. We'll define the array in a separate script, save it to a global variable, and then use the
Add_Locations
variable to trigger the addition of new entries to the array.Step 1: Define the Array and Save to Global Variable
First, let's create a script to define the array and save it to a global variable.
Step 2: Add to Array Function
Next, let's create the function to add new entries to the array when
Add_Locations
is true.Step 3: Trigger the Addition with Add_Locations
Finally, let's create a script that continuously checks for the
Add_Locations
variable and calls theaddToArray
function when it's true.Putting It All Together
Add_Locations
variable and add new entries.Example Usage
Here's how you can use the scripts together:
Define Array Script:
Add to Array Function:
Trigger Addition Script:
Notes:
Add_Locations
variable is correctly set totrue
when you want to add a new entry.v26
,v27
,v1
) as per your setup.Add_Locations
variable totrue
.This approach ensures that new entries are added to the array whenever the
Add_Locations
variable turns true, and you can see the added locations in the debug output. If you have any further questions or need additional assistance, feel free to ask!I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
@Athena Got the add locations function working properly, thanks. Learned some things along the way. Now I'd like a separate function that I will put into a different script to print out the entire array whenever I want to. This will help with debugging and verifying all of the entries were placed in there properly.
Here's the corrected markdown for your content:
Great to hear that the add locations function is working properly! Now, let's create a separate function to print out the entire array whenever you want to. This will help with debugging and verifying that all entries were placed correctly.
Print Array Function
Here's the function to print the entire array:
Example Usage
You can call this function from any script to print the entire array. For example, create a new script and call the
printArray
function:Putting It All Together
Add the Print Array Function: Include the
printArray
function in your main script or a separate script file.Create a Script to Call the Function: Create a new script that calls the
printArray
function whenever you want to print the array.Example Usage
Here's how you can use the scripts together:
Print Array Function:
Script to Call the Function:
Notes
ItemsArray
global variable is correctly set and contains the array.printArray
function from any script to print the entire array.This approach ensures that you can print the entire array whenever needed, helping you verify and debug the entries. If you have any further questions or need additional assistance, feel free to ask!
I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.