#Code Level limit hack with Switch Code level.

1 messages · Page 1 of 1 (latest)

opaque ether
#

I use the code level limit hack all the time but ran into an issue tonight when trying to use two code levels inside Switch that uses code (so 3 code levels). The hack keeps the macro from bugging out, but it also fails to run the nested code in the correct switch option. You'll see the broadcasts from the second and third level do not run ```[h: switchOption = "test"]
[h: var1 = 1]
[h: var2 = 2]

[h, SWITCH(switchOption), CODE:
case "test":
{
[h: broadcast("Test Switch Code block starts.")]
[h, if(var1 == 1), CODE:
{
[h: broadcast("Second Code Level.")]
[h, if(var2 == 2), CODE:
{
[h: broadcast("Third Code Level.")]
};
{
[h:'Fix for code level limitation.']
}
]
};
{
[h:'Fix for code level limitation.']
}
]
[h: broadcast("Test Switch code block ends.")]
};
default:
{

    }

]

[h: broadcast("Code after the Switch.")]

Has anyone used the hack with a switch with code before?
opaque ether
#

@true jasper Sorry for the ping (since I know you don't come here much any more) but I figure if anyone knows the answer to this it would be you. 😉

opaque ether
#

I'm actually having trouble doing anything more than 3 levels deep (outside a switch) using the hack right now... ```[h: level1 = 1]
[h: level2 = 2]
[h: level3 = 3]

[h, if(level1 == 1), CODE:
{
[h: broadcast("First Code Level.")]
[h, if(level2 == 2), CODE:
{
[h: broadcast("Second Code Level.")]
[h, if(level3 == 3), CODE:
{
[h: broadcast("Third Code Level.")]
};
{
[h:'Fix for code level limitation.']
}
]
};
{
[h:'Fix for code level limitation.']
}
]
};
{
}
]

[h: broadcast("Code after the nesting.")]``` Works.

#

But with four levels it does not process the two inner levels. Notably, it does stop it from throwing an error though. ```[h: level1 = 1]
[h: level2 = 2]
[h: level3 = 3]
[h: level4 = 4]

[h, if(level1 == 1), CODE:
{
[h: broadcast("First Code Level.")]
[h, if(level2 == 2), CODE:
{
[h: broadcast("Second Code Level.")]
[h, if(level3 == 3), CODE:
{
[h: broadcast("Third Code Level.")]
[h, if(level4 == 4), CODE:
{
[h: broadcast("Fourth Code Level.")]
};
{
[h:'Fix for code level limitation.']
}
]
};
{
[h:'Fix for code level limitation.']
}
]
};
{
[h:'Fix for code level limitation.']
}
]
};
{
}
]

[h: broadcast("Code after the nesting.")]```

#

I thought we used to be able to go more than 3 levels deep using the hack... so either my hack syntax is off or something changed. But four levels this way doesn't work 1.15+ (I don't have anything earlier installed.)

sand swift
#

I thought the hack involved 2 single quotes, '' somewhere in the mix.

opaque ether
sand swift
#

The ; {' '} is unnecessary. ;{} is sufficient I believe. it's only done when there is a no false option to complete the if() syntax.

opaque ether
# sand swift The ; {' '} is unnecessary. ;{} is sufficient I believe. it's only done when the...

Can you show me code where it's unnecessary? Three deep breaks without it in my tests. As far as I know the key is to have the '' in the else statement and you can hide it by wrapping it in h:. You also only need it on the inner levels. As far as I can tell, the root cause for not being able to use the trick with SWITCH is because there is no else... which isn't to say there isn't a way around it... I just can't find it and was hoping someone who understood the parser better might have a solution.

I'm also pretty sure you used to be able to go more than 3 deep (as the article mentions), and now I can't (as the examples I provided above illustrate.) It's altogether possible that my simplification of the trick is "breaking" it, but if it is I'd like to see code that doesn't.

If it only works for one extra level now, that's fine... one extra is often all I need 99% of the time to simplify things... but I just ran into an issue where I wanted that "extra level" in a SWITCH and it can't be done because the switch is consuming a level.

sand swift
#

I can't get the example to work so something probably changed, like it was destined to.

#

That's the problem with hacks.

opaque ether
#

O-well. It still works for an extra code level by just populating the inner level else's (which is how I've always used it so I never noticed it failing). No idea when the wiki example stopped working, but it doesn't work as far back as 1.15. 🤷‍♂️

As an aside... Wolph said he used it a lot in his code... so I'm surprised there isn't more breaking in the BoT.

dense barn
#

I'm only guessing but when there were adjustments to the parser, perhaps not only extra) but this too?

sand swift
#

As far as I can tell the use of '' ends up quoting the code and I'm not entirely sure it works as intended, but may look like it does.

opaque ether