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 I tried to run the program but it gave me an error message -setTimeout is not defined. I tried to setVar("$setTimeout", setTimeout); but it did not help. Rather than setting the servos to move within that script I want the locations of the array put into these variables xready, yready, zready. This will allow me to experiment with the array without actually moving servos. I can easily move the servos with "move to position" to the variable (xready) in Blockly after I am comfortable that it is moving appropriately. Please adjust the function.
Given the constraints within ARC's scripting environment, including the lack of support for
setTimeout
and direct user prompts as you'd find in standard JavaScript environments, we'll need to adapt the approach. ARC's scripting capabilities, particularly with JavaScript or Python, are designed to work within a robotics context, which means some web-based functions likesetTimeout
orprompt
are not available directly.For the purpose of setting variables (
xready
,yready
,zready
) with the array values and allowing for experimentation without directly moving servos, we can modify the approach as follows. This example will focus on iterating through the array and setting the variables without delays, as implementing asynchronous delays likesetTimeout
would in a web environment isn't directly supported in ARC's scripting environment.Adjusted Function for ARC
Notes:
objectLocations
array and sets the ARC variables$xready
,$yready
, and$zready
with the location values. You can then use these variables in Blockly or other parts of your ARC project.setTimeout
, this script will execute synchronously. If you need to introduce delays between setting the variables, consider using ARC's scripting capabilities to trigger this script multiple times with pauses in between, or explore ARC's native timing and control commands.This approach should allow you to experiment with the array and servo movements without directly moving the servos until you're ready. Remember, ARC provides a rich set of tools and commands for robotics programming, and leveraging those will often provide the best results within its environment.
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 think we need to change the terminology of console.log(
Replaying: ${location.name} at x=${location.x}, y=${location.y}, z=${location.z}
); because it states that console is not defined. I do not think that console.log is allowed in ARC. The rest of it looks good though.You're correct that ARC's scripting environment does not support
console.log()
for outputting text to a console, as you would in a standard web development environment. Instead, ARC provides different methods for displaying messages or logging information.For JavaScript or Python within ARC, you can use the
print()
function to output text to the ARC's debug log. This is useful for debugging purposes or simply to track the flow of your script.Let's adjust the script to replace
console.log()
withprint()
for compatibility with ARC:This script now uses
print()
to output messages, which is compatible with ARC's scripting environment. Theprint()
function will display messages in ARC's debug log, allowing you to see the output of your script as it runs.Remember, the
setVar()
function is used to set global variables within ARC, and these variables can be accessed by other scripts or controls within your ARC project. This approach allows you to experiment with the array and servo movements by setting thexready
,yready
, andzready
variables without directly moving the servos until you're ready.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.
Yes, I've noticed a couple times over the past few weeks while I'm learning Javascript that Athena has suggested to me to use the console.log() command to view output messages. It didn't work for me either. I've been using the Print() command with EZ Script for years to view information stored in variables so I tried it in Javascript scripts and found it work as expected.
It's Console.log that's why it messes her up
Wow that's all it is a capital C, that's the first I've heard of this one and this will help. Thanks
Console.log() is just a fancy way of using print()