#Trying to Call a Macro from JS

1 messages · Page 1 of 1 (latest)

red knot
#

I have a similar macro with nearly identical code that works, so not sure why this one is throwing this error.

Here's the code snippet:

[h: vMacroLinkText = macroLinkText("Thunderstrike Echo@lib:Weather SFX", "none")]

[overlay(overlayName, zOrder): {
  r[: '
<html>
<head>
  <meta charset="UTF-8">
  ' + css + '
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
  <div class="thunder-container">
    <div class="lightning"></div>
  </div>
  <script src="script.js"></script>
  <a id="runMacro" style="display:none" href="[r: vMacroLinkText]">/<a>
  <script>
  let runMacro = document.getElementById("runMacro");
  function playSound() {
      runMacro.click();
  }
  const intervalID = setInterval(playSound, 5000);
</script>
</body>
</html>
']
}]

It starts running okay, and then every time it hits the interval (5 second) mark, it pops the error in the screenshot. 🙁

Thanks for any help!

echo grove
#

One syntax issue I see quickly r[: '

red knot
#

Still same error. Here's the complete code block (if it lets me post the whole thing):

[h,if(argCount() > 0): overlayName = arg(0); overlayName = "fx0"]
[h,if(argCount() > 1): zOrder = arg(1); zOrder = 0]
[h,if(argCount() > 2): layerOpacity = arg(2); layerOpacity = 1]

[h, if(json.type(macro.args) == "OBJECT"): json.toVars(macro.args)]
[h: vMacroLinkText = macroLinkText("Thunderstrike Echo@lib:Weather SFX", "none")]

[overlay(overlayName, zOrder): {
  r[: strFormat('
<html>
<head>
<style>
body {
margin: 0;
height: 100vh;
background: #000;
overflow: hidden;
}

.thunder-container {
  position: relative;
  width: 100%;
  height: 100%;
}

.lightning {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: white;
  opacity: 100;
  animation: flash 5s infinite, shake 5s infinite;
}

@keyframes flash {
  0%, 100% {
    opacity: 0;
  }
  10%, 30% {
    opacity: 1;
  }
  20%, 40% {
    opacity: 0;
  }
}

@keyframes shake {
  0%, 100% {
    transform: translate(0, 0);
  }
  15%, 45% {
    transform: translate(-10px, 10px);
  }
  30%, 60% {
    transform: translate(10px, -10px);
  }
}
</style>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
  <div class="thunder-container">
    <div class="lightning"></div>
  </div>
    <a id="runMacro" style="display:none" href="[r: vMacroLinkText]"></a>
  <script>
  let runMacro = document.getElementById("runMacro");
  function playSound() {
      runMacro.click();
  }
  const intervalID = setInterval(playSound, 5000);
</script>
</body>
</html>
')]
}]
echo grove
#

This is the syntax I'd use ```[h,if(argCount() > 0): overlayName = arg(0); overlayName = "fx0"]
[h,if(argCount() > 1): zOrder = arg(1); zOrder = 0]
[h,if(argCount() > 2): layerOpacity = arg(2); layerOpacity = 1]

[h, if(json.type(macro.args) == "OBJECT"): json.toVars(macro.args)]
[h: vMacroLinkText = macroLinkText("Thunderstrike Echo@lib:Weather SFX", "none")]

[h: css = "
body {
margin: 0;
height: 100vh;
background: #000;
overflow: hidden;
}

.thunder-container {
position: relative;
width: 100%;
height: 100%;
}

.lightning {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: white;
opacity: 100;
animation: flash 5s infinite, shake 5s infinite;
}

@keyframes flash {
0%, 100% {
opacity: 0;
}
10%, 30% {
opacity: 1;
}
20%, 40% {
opacity: 0;
}
}

@keyframes shake {
0%, 100% {
transform: translate(0, 0);
}
15%, 45% {
transform: translate(-10px, 10px);
}
30%, 60% {
transform: translate(10px, -10px);
}
}
"]

[h: js = "
let runMacro = document.getElementById('runMacro');
function playSound() {
runMacro.click();
}
const intervalID = setInterval(playSound, 5000);
"]

[overlay(overlayName, zOrder):
{
<html>
<head>
<style>
[r: css]
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="thunder-container">
<div class="lightning"></div>
</div>
<a id="runMacro" style="display:none" href="[r: vMacroLinkText]"></a>
<script>
[r: js]
</script>
</body>
</html>
}
]```

red knot
echo grove
#

I try not to use strFormat unless it's necessary... I don't think it produces more readable code and can cause issues that require additional debugging.

dusk cobalt
# echo grove I try not to use `strFormat` unless it's necessary... I don't think it produces ...

I was going to ask one of the devs on this because I ran my code through chatGPT and it said you should use strformat any time you're dealing with concatenating strings.

I know in the above case, it doesn't matter. However. AI stated that if you do NOT use strformat, the parser attempts to "calculate" things when you use "+".

eg.
sVar = "this really long string"
tVar = "this second string even longer"

This is better: [endVar = strformat('%{sVar} %{tVar} more text you want to add')]
AI said this is bad: [endVar = sVar+tVar+'more text you want to add')]

echo grove
red knot
red knot
#

The culprit seems to primiarily be wth js functions like this inside the [h: jss = ""] block.

drop.style.transform = `translate(-50%, -50%) rotate(${angle}deg)`;
torpid sierra
#

Try escaping the $

#

The MT parser does something with unescaped $

echo grove
#

If your JS has special characters in it, it's best to do as Baaaaaz suggests... you can also put JS into a property and use getProperty() to pull the plain text. Basic JS with no special characters can go into the local macro as I did above.

red knot
echo grove
#

yes

red knot
#

Okay, as simple as this code is, I'm getting a parser error... I know I'm gonna feel pretty dumb after I realize my mistake, but here goes:

[h,if(isOverlayRegistered("Thunder")), code:
{
    [h: execFunction("closeOverlay", "Thunder"), 0, "all"]
};{
    [h: link = macroLinkText("New Thunder WIP7@Lib:weather", "none")]
    [h: execLink(link, 0, "all")]
}]

Only getting the error if the overlay is registered (true).

org.antlr.v4.runtime.misc.ParseCancellationException

Thanks!

verbal comet
#

[h: execFunction("closeOverlay", "Thunder"), 0, "all"]

#

) in wrong spot

red knot
verbal comet
#

[h: execFunction("closeOverlay", "Thunder", 0, "all")]