#Conditional Error

1 messages · Page 1 of 1 (latest)

elder crane
#

So, chatGPT hasn't been much help troubleshooting this issue, but I'm a conditional error with the following conditional snippet:

[h: vMacro = getMacroName()]
[h: vLoc = getMacroLocation()]
[g,if(!json.isEmpty(macro.args)), code:
{
    [g,if(json.get(macro.args, 0) == "Minimize"), code:
    {
        [h: vSize = 20]
        [h: vCenter = divide(vSize, 2)]
        [h: vCloseCoords = vCenter + "," + vCenter + "," + vCenter]
        [h: toggleImage = tableImage("My Dice Roll Overlay", 6, vSize)]
        [h: expandDiceOverlay = macroLinkText(vMacro + "@" + vLoc,"all", "Maximize")]
        [r,overlay("Dice Overlay", "zorder=5;"):{
        <style>
            [r: '.close {background-color: lightgreen;display: grid;place-items: center;left: 50%; transform: translate(-50%);position: absolute;}']
        </style>
        <div class="close" style = "background-color: red"><img src="[r: toggleImage]" style="--pointermap:blockopaque;" draggable=false usemap='#closeIcon'></div>
        
        <map name="closeIcon">
          <area shape="circle" coords="[r:vCloseCoords]" href="[r: expandDiceOverlay]" title="Click to Maximize">
        </map>}]
        [return(0)]
    }]
};{}]

Here is the error its' throwing:

   Error in roll for IF option.       Statement options (if any): g,if(!json.isEmpty(macro.args)), code       Statement Body (first 200 characters): { [g,if(json.get(macro.args, 0) == "Minimize"), code: { [h: vSize = 20] [h: vCenter = divide(vSize, 2)] [h: vCloseCoords = vCenter + "," + vCenter + "," + vCenter] [h: toggleImage = tableI
Error trace : Dice Overlay WIP@{name='Dice Overlay WIP, location='MainLibToken, source='library'}

Any help would be much appreciated!

oblique viper
#

I think it is because you have an overlay nested in an already nested code block. Three levels of nesting for curly braces is too many. You may have to factor that overlay out of your nested code block.

#

It looks like the reason you've nested them is so you can avoid an error from json.get in case the json object is empty. You can just purposefully abort(!json.isEmpty(macro.args)) before the block to reclaim a nesting level.

#

(abort stops on falsy values, so you have to invert the isEmpty value to get the stop behavior you want.)

#

Alternatively, since it looks like you're using return, you could do a standalone if > return:

[g,if(json.isEmpty(macro.args)): return(0)]

(or whatever desired return value is)

#

Anything to break before you get to your overlay code so you can reduce the nesting level 🙂

elder crane
oblique viper
#

Then just set a variable based on json is empty and check for that with an and

#

You to somehow have to factor out the nested level and there's lots of ways

#

Though since you use the return statement after calling the overlay, I don't see why you can't do that ahead of time

elder crane
oblique viper
#

I guess the question I have is why do you need the macro to complete even if that code block doesn't engage? Nothing happens after that

elder crane
oblique viper
#

Ah! Then yes, factor out your is empty and JSON.get calls into a new vMiminize variable and check that instead.

#

You can just do all the figuring ahead of time.

elder crane
oblique viper
#

Storing a condition like that is often good practice anyway to make code more explicit. 🙂