Im learning JS programming but Im completely new and not familliar with terms and usage yet. Im coding macros and I want to substitute STRVALUE for var V1.
Can someone hint how to use variables in getString?
Its meant to run SCRIPT1 upon detecting XXX in chat, but Im adding alot of possible scripts. I would love to combine two or more variables instead of STRVAL. something like STRVAL== "V1 + V2 or V3"
var V1 = XXX
var V2 = Y
var V3 = Z
if (event.text.getString() == "STRVAL")
JsMacros.runScript("SCRIPT1.js")
Im running different Scripts depending on String output and I have to include STRVAL for each if statement, after every runScript like
if (event.text.getString() == "STRVAL1")
JsMacros.runScript("SCRIPT1.js")
if (event.text.getString() == "STRVAL2")
JsMacros.runScript("SCRIPT2.js")
if (event.text.getString() == "STRVAL3")
JsMacros.runScript("SCRIPT3.js")
I would like to use shortcut ID's of Variables just including on top.
var V1 = XXX
var V2 = Y
var V3 = Z
Thanks for help, as I said Im really green with JS yet.
First of all string variables are diclared with cotes ("" or '') so when declaring the V1,V2 and V3 you should write :
var V1 = 'XXX'
var V2 = 'Y'
var V3 = 'Z'
now for if statement i belive you need to know how includes() works it returns a boolean variable that determines if a string contains another string
eg:
"Hello word".includes("word")
> true
so it's perfect for you case like so :
var V1 = 'XXX'
var V2 = 'Y'
var V3 = 'Z'
if (event.text.getString().includes(V1 + V2))
JsMacros.runScript("SCRIPT1.js")
or with arrays (it's pretty much the same)
if ([V1 + V2 , V3].includes(event.text.getString()))
JsMacros.runScript("SCRIPT1.js")
Good luck learning Js