Vertical Servo icon Vertical Servo — Drag vertically to control a servo within set min/max limits; center, release, invert, and mirror to other servos. For 3-wire GVS servos. Try it →
Asked
Resolved Resolved by Athena!
1 Participant
Setvar Global Variable Quotes?

Setvar Global Variable Quotes?

In ARC JavaScript, what is the proper way to set the value of a global variable - with or without quotes? Both seem to work.

I'm using ARC's JavaScript scripting (setVar) in an ARC project to set a global variable. Example code:

setVar("$anamationStatus", 0)

setVar("$anamationStatus", "0")

If there is a difference, and it matters, why?



Related Hardware (view all EZB hardware)
EZ-B V4 by EZ-Robot
EZ-B v4 with Synthiam ARCx controls servos, sensors, camera and audio over Wi-Fi or USB serial, no firmware needed.
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

Related Robot Skills (view all robot skills)
Script by Synthiam
Multi-language ARC Script: build, run and debug Blockly, JavaScript, EZ-Script or Python with Intellisense, run/save/load and Roboscratch support

ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#1  

Yes - both can "work," but they do different things in ARC JavaScript.

The correct rule

Use:

setVar("$anamationStatus", 0);

when you want the global variable to be a number.

Use:

setVar("$anamationStatus", "0");

when you want it to be a string.

Why this matters

ARC global variables are typed by the value you store:

  • 0 = numeric zero
  • "0" = text containing the character zero

They may look the same when displayed, but they are not the same value type.

Example differences

setVar("$myValue", 0);
setVar("$myText", "0");
  • getVar("$myValue") returns a number
  • getVar("$myText") returns a string

That matters when you later compare, calculate, or make logic decisions:

if (getVar("$myValue") == 0) {
  print("numeric zero");
}

if (getVar("$myText") == "0") {
  print("string zero");
}

Best practice in ARC

If the variable represents a state, count, index, speed, or anything numeric, store it as a number:

setVar("$animationStatus", 0);

If it represents labels, names, or text, store it as a string:

setVar("$statusMessage", "ready");

Why you may think both work

Because ARC will often display them similarly in the variable watcher, and JavaScript can sometimes coerce types during comparisons. But relying on that can cause subtle bugs later.

Recommendation

For status flags like your example, I’d suggest using a number unless you specifically need text:

setVar("$animationStatus", 0);

If you want to make the meaning clearer, you could even use:

setVar("$animationStatus", "stopped"); // text state

or a numeric convention like:

setVar("$animationStatus", 0); // 0 = stopped, 1 = running

One more thing

I noticed the variable name is spelled anamationStatus in your example. If that’s accidental, I’d fix the spelling to avoid confusion later.

If you want, I can also show you the best ARC pattern for using global status variables in multiple scripts. Questions like this are often a great fit for the ARC AI Assistant inside the script editor as well:
https://synthiam.com/Products/AI-Assistant

I am a customer support AI and still learning. Please verify important answers in our support documentation. For advanced AI features, use the AI Script Agent built into ARC.
#2  

Just what I needed to know. I appreciate this information.

📚 This thread has been preserved as a helpful resource!

While new comments are no longer being accepted, the information here remains available for learning and reference. Check the most recent comment for additional details.