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
You're welcome! I'm glad you found the solution helpful and understandable. If you have any more questions or need further assistance in the future, feel free to reach out. Happy robot building!
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 , Can you explain the following javascript command and when to use it? I don't understand why you used it in the above script you wrote. Is this the only way to set a object as a variable?:
setVarObject();
@Athena , nevermind answering my last question. I looked in thw support section under the Javascript and found this that explained everything:
setVarObject( variableName, value )
Sets the value from Arc’s public global variable storage of the object. This allows the variable to be available to other robot skills or scripts using getVar(). (Read More). This is different than setVar() because it sets the value as an object without any translation. So you can pass entire objects, such as functions, classes, or multidimensional arrays. - The name of the global variable as a string - The object value that you wish to store in the global variable Example: // Set the multidimensional array to be accessible by other robot skills with getVar() x = [ [0, 1, 2], [3, 4, 5] ]; setVar($MyValue, x);
Great to hear that you found the information you needed!The
setVarObject()
function is indeed very useful for storing complex data structures like objects and multidimensional arrays in ARC's global variable storage. This allows you to share these complex data structures across different robot skills and scripts within your project.If you have any more questions or need further assistance, feel free to ask. Happy coding!
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 I have experimented and double checked with the multiple scripts and have found a glitch. It always starts with first name on the array rather than the start name. It then continues on for the amount of iterations passed the startname. It is supposed to have the startname be the first array that the servos go to. Any recommendations to fix this?
To address the issue where the script always starts with the first name in the array rather than the specified start name, you can modify the script to find the index of the start name and begin the iteration from that index. Here’s how you can do it:
Here’s an example of how you can achieve this in JavaScript:
Explanation:
namesAndValues
array contains names and their corresponding x, y, z values.startIndex
variable holds the index of the start name.startIndex
and iterates through the array, moving the servos to the specified positions.Notes:
startName
exists in the array to avoid starting from an invalid index.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. 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 I was looking over your array on July 7th post #127 and that should have worked to start with the startName that was declared in a different script. Here is the code that you posted var startName = getVar("$Start_Name");
As soon as you start the script it should go to the location of the startName . What could be the reason that it is not going there? I double checked the variable with smart variable watcher and it has one of the names in the array in it.
It sounds like the logic should work as intended, but there might be a small issue with how the
findIndex
function is being used or how the variable is being accessed. Let's go through a few troubleshooting steps to ensure everything is set up correctly.1. Verify the Array Structure
Ensure that your array structure matches the expected format. For example, if your array is structured as follows:
2. Verify the Start Name Variable
Ensure that the
startName
variable is correctly retrieved from the global variable storage:3. Find the Start Index
Ensure that the
findIndex
function is correctly finding the index:4. Iterate from the Start Index
Ensure that the iteration starts from the correct index:
Full Example Code
Here is the full example code with debugging lines added:
Troubleshooting Steps
$Start_Name
variable is correctly set and matches one of the names in the array.print
statements to verify that thestartName
andstartIndex
are correctly retrieved and calculated.name
,x
,y
, andz
properties.If the issue persists, please provide more details about the array structure and the exact values being used, and I'll be happy to assist further!
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.