Asked
— Edited

@Athena When I write a script using Javascript and I want to set a variable what command should I use. I've used both setVar and simply just Var. Both have worked for me.
For example I have this in my INT Script that runs when my project starts:
setVar( "$adcSoilSpecified", 200 );
And I have this in a stand alone script that operates a motor and watches an encoder:
var Get_Lft_Elbow_P = "2, Getp\r";
UART.hardwareUartWrite(0,Get_Lft_Elbow_P.length,2); //UART 0 on EZB 2
Which is the correct one to use and what is the difference between the two?
Related Hardware EZ-B v4
That all makes a lot of sense and has answered my question. Thanks for the lesson and help.
@Athena I'm trying to write a script in ARC that's written in JavaScript. Once running and at a needed point I want the script to stop and wait for a global variable to change before resuming. In my case I want the JavaScript to watch the AutoPosition control variable "$AutoPositionStatus" change from 1 (running) to 0 (Stopped). What is the best way to do this and what would the Javascript code look like?
In Ez Script there is a "Wait" function bit I can't find one for Javascript.
In JavaScript within ARC, you can use a loop to periodically check the value of a global variable and pause the execution of the script until the variable meets your condition. Since JavaScript in ARC does not have a built-in wait function like EZ-Script's
WaitForChange()
, you'll need to implement this functionality manually.Here's an example of how you might write such a script to wait for the
$AutoPositionStatus
variable to change from1
to0
:In this script, the
sleep()
function is used to create a delay without blocking the entire ARC application. It's important to note that this is a busy-wait loop, which means it will consume CPU resources while waiting. The delay should be short enough to check the variable frequently but long enough to avoid high CPU usage.The
waitForAutoPositionStatus()
function contains a loop that continuously checks the value of$AutoPositionStatus
using thegetVar()
function. If the value is not0
, the script pauses for a short time using thesleep()
function before checking the variable again.Once the
waitForAutoPositionStatus()
function detects that$AutoPositionStatus
has changed to0
, it breaks out of the loop, and the script continues with any subsequent commands you wish to execute.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.
Sometimes AI is bad at programming... Well, mostly is bad at programming..
Dave, just do this..
or if you don't like using the word "true", it's the same as a 1 and "false" is the same as a 0 (zero)
Thanks once more @DJ. That was an elegant solution and worked great. I've used "do - while" tree but I didn't think to use just "while" to hold the script.
@Athena in DJ's last Javascript code example above he shows how to hold a script using "While" and then watch one global variable for change so the script will restart. How would I add a second variable to that one line so it will watch and wait for both variables to change?
To wait for two global variables to change in JavaScript within ARC, you can use a
while
loop that checks both conditions. If you want the script to resume when both variables reach a specific value, you can use the logical AND operator (&&
) to combine the conditions.Here's an example of how you might modify the script to wait for both
$AutoPositionStatus
to change to0
and another variable, let's say$AnotherStatus
, to change to0
as well:In this script, the
while
loop will continue as long as either$AutoPositionStatus
is1
or$AnotherStatus
is1
. The loop will only break (allowing the script to continue) when both variables are0
.If you want the script to resume when either of the variables changes to
0
, you can use the logical OR operator (||
) instead:In this case, the
while
loop will break if either$AutoPositionStatus
becomes0
or$AnotherStatus
becomes0
, and the script will continue.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.
Reposted so Athena can see my edited changes.