https://perchance.org/8swe0svvsk#edit
The same exact call in a code block vs a script tag behaves differently. The values seem to arrive to the plugin okay, but then get funky at some point–no idea why.
https://perchance.org/8swe0svvsk#edit
The same exact call in a code block vs a script tag behaves differently. The values seem to arrive to the plugin okay, but then get funky at some point–no idea why.
Okay I think this is the last update… the problem is, accessing a property of a perchance object. If I can avoid that, then it doesn’t auto-strip escapes.
I noticed this function:
__evaluateText
which takes a root object as the context, a “this” object, and a string to evaluate. So I’m using that now, which also means I can use any object to evaluate against too! And I can pass itwindow
or$root
(orthis
includes both it seems?). And no need for the YOLO hack, because that whole thing is bypassed anyway. 👍Here’s my test for this method: https://perchance.org/elbvabvg9g#edit. (Didn’t even need an iframe to isolate it either!)
I’ve now integrated this into my advanced image-gen plugin.
__evaluateText
is an engine-internal thing, and your code could break if you rely on that. In general, in JS, you should only use variables/functions that begin with_
if you were the one that made it. But it’s my bad because I can’t expect people to know that, and it’s my bad for leaving it accessible - I need to tidy up all those globals. I’ll add a warning for generators that use it, and now that I know people could be using stuff like this, I’ll make sure to keep these functions around as much as I possibly can (seems possible for__evaluateText
, but there are other internal functions that may be much harder to keep).So what I’m gathering from the various comments in this thread is that there are two thing to report:
evaluateItem
(which can be called on strings like"{1-2}".evaluateItem
), except it should allow passing in a “root”? So like"[b]".evaluateWith(newRoot)
wherenewRoot
was created withcreatePerchanceTree
? Sob
gets pulled fromnewRoot
. This seems like a fair request. How important is it for you to also be able to choose thethis
reference? E.g. do you need/want"[b]".evaluateWith(newRoot, parent)
?foo = \n
, and you write[console.log(foo)]
then it logs the literal characters\
andn
whereas if you write<script>console.log(foo)</script>
then it logs a newline character. Example: https://perchance.org/9tffz7swhn#edit I think I actually designed it like this on purpose so that you don’t have to add extra backslashes before characters depending on how “deeply” you’ve referenced it:output output: [depth1] depth1 depth1: [depth2] depth2 depth2: \\n
https://perchance.org/0u6l500kua#edit
If I fixed this “bug” then it would output a newline instead of the literal
\n
characters. With the current code, no escape-character-stripping is done in square block evaluation - it’s instead done when the square block’s output actually gets placed into the HTML. I.e. processing escaped characters is only done right at the end. This means that if you refactor your code and the depth of “references” to various items changes, then you don’t have to go through and add/remove backslashes.But I agree that the inconsistency of behavior here RE script tags is very strange. This seems big enough that it may have to wait for v2 of the engine though - I’m struggling to think of a way to fix this without causing some generators to break. If you have any thoughts here, please let me know, and thanks for your in-depth exploration here! It’s very helpful. I’ll link this comment from the perchance.org/known-bugs page.
Honestly, I think the real issue is that everything is monkey-patched. Which means you cannot escape everything getting “perchanced” all over the place. Which means if you want things to work “normally” you have to re-escape everything just in case. And even then it might blow up–who knows?
If there was simply a difference between a string made with perchance (or explicitly perchance-ified), which has all the extras attached, and a string you just make in JavaScript, then none of this would be an issue. (Is my guess.) And same goes for all objects. Like, nothing is monkey-patched unless it’s perchance-ified, and then it works in the perchance-y way.
There’s a lot of head-scratching, frustrations, and table-flipping that happens when I do certain things in simple JS that’s then “taken over” or otherwise messed with by the perchance engine. There are so many caveats and edge cases and weird behaviours you wouldn’t expect if you actually know JS, know what I mean?
I understand the goal of all these things is to make it easy for non-programmers who don’t know JS to use it. But if you do know JS at times it can feel like you’ve stepped into bizarro-land where everything is upside-down and all your knowledge and skill just works against you. 😂😭😵💫
Wait, this sounds like a separate bug report. The issue I’m talking about is (I thought) only relevant to Perchance nodes, not raw strings. Can you give an example where Perchance interferes with your <script> tag where the text you’re manipulating doesn’t come from a Perchance node/property?
The example I linked you to in the original post uses pure JS to produce the problem, yes. 😅 https://perchance.org/8swe0svvsk#edit
The original issue was a script tag passing a JS-made string into a function. Versus a code block passing a JS-made string into a function. The same exact string, declared in JS. But the function call was from a script tag vs from a code block. That JS-made string would evaluate differently depending on whether a script was being processed at the time or a code block was being processed at the time. Something like that.
Oh, right, yes, when using
evaluateText
on said string, that makes sense - due to square blocks having the policy of always “saving escape-char-processing until right at the end” as mentioned above. And yeah I agree this inconsistency is very annoying!Yeah I did realise it’s an internal thing. But, if that’s the only way of me making it work without just copying that entire function someplace, then it’ll do. I actually like being able to see and use those internal things. Lets me sort out my own solutions to weird fiddly things like this. (Albeit with a lot of studying and stepping through to even figure out how to use it 😂)
If you just make a set-in-stone function like you did for
createPerchanceTree
that would be find with me to be honest. Or yeah, a method on strings.I didn’t personally need a
this
for what I’m using it for, but if it’s just as easy to add that in as an optional parameter that would be good. Oh, and theroot
should just be any object, really. In my plugin I’m allowing people to use things like window, or an object, etc. So… please don’t throw if it’s not actually a root. Just let any object be used to “evaluate against.” Same goes forthis
I guess.I could see it could break a load of things, as you said. It’s likely only an issue because I was specifically doing deeper perchance stuff like building roots and evaluating strings myself. Probably most people won’t even find this discrepancy or notice it.