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
what do u mean dave? give an example of what ur struggling with
Well, not really a struggle just to search. After I write a script in the editor a lot of times I need to go back and find a word or sentence that I need to change. If it is a long script it's hard to find the exact phrase I need to find to change. If there was a search tool like there is in The command API section of ARC it would be easier to find this command I need to edit. Does that make any sense?
Hey Dave
Sure DJ will have a much better solution buttttttttt. Unless I'm having a brain fart right now about this question, I always keep a backup copy of my scripts in a .txt file. If you need to find a word or line you can just look in the "find" section of the .txt editor? This should work but there might be a much better way?
I am trying to learn Python now and changing scripts is a way to help learn and work on the bot at the same time.
Good luck!
Thanks Herr. That's a great idea. Thanks.
Both ARC and ARCx have a search feature in the editor. Get the list here: synthiam.com/Support/Programming/code-editor/editor-shortcuts-keys
In ARC, press CTRL-F for SEARCH (press F3 to continue the search with last search parameters)
CTRL-H is replace
CTRL-G is goto line number (helpful to jump to a line when you get an error message)
@Athena Still having a bit of an issue the function being undefined and it starts all over again. Have been using // Check if objectLocations is undefined. If so, initialize it. if (typeof objectLocations === 'undefined') Have even put setVarObject( "$objectLocations", objectLocations ); to make sure it is a global variable and it stores last name with coordinates onto the array. I run the program and it shows up on the debug menu fine. I then get out of the script and run new set of name with x, y, z postions into the variables addLocation (getVar("$name"),getVar("$xPos") ,getVar("$yPos"),getVar("$zPos")); that should be pulled into the array on the next script run. I run the script again but it just overwrites the last name with coordinates. It should have just added it to the bottom. What am I doing incorrectly?
It seems like the issue you're encountering with the
objectLocations
array not retaining its values across script runs is due to the scope and persistence of variables within ARC's scripting environment. Each time you run the script, it initializes a new context, meaning any variables declared within that script are reset. To achieve the persistence of theobjectLocations
array across different runs of the script, you need to utilize ARC's global variable system effectively.Here's a revised approach to ensure
objectLocations
retains its values between script executions:Initialization Check: First, check if the global variable
$objectLocations
exists and has been initialized. If not, initialize it as an empty array.Add Location Function: Define a function to add a new location to the
objectLocations
array. This function will retrieve the current array from the global variable, add the new location, and then update the global variable.Usage: Use the
addLocation
function to add new locations to the array.Here's how you can structure your script:
Important Notes:
getVar
andsetVar
correctly to interact with global variables. The first argument should be the global variable name as a string (e.g.,'$objectLocations'
).getVar
andsetVar
can handle complex objects and arrays directly. If ARC's scripting environment has limitations on what can be stored in global variables, you may need to serialize the array to a string format before storing it and deserialize it when retrieving. Use JSON.stringify() for serialization and JSON.parse() for deserialization if necessary.By following this approach, you should be able to maintain the
objectLocations
array across different script runs, allowing you to accumulate locations without overwriting previous entries.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 may have found the problem. While looking over the smart variable watcher noticed there were 6 different references to $objectlocations. Not sure how that happened but pretty sure will need to get rid of them to have a clean slate. How do I get rid of those and start fresh and how do I avoid this in the future as they were all named exactly the same.