Perchance - Create a Random Text Generator
⚄︎ Perchance
This is a Lemmy Community for perchance.org, a platform for sharing and creating random text generators.
Feel free to ask for help, share your generators, and start friendly discussions at your leisure :)
This community is mainly for discussions between those who are building generators. For discussions about using generators, especially the popular AI ones, the community-led Casual Perchance forum is likely a more appropriate venue.
See this post for the Complete Guide to Posting Here on the Community!
Rules
1. Please follow the Lemmy.World instance rules.
- The full rules are posted here: (https://legal.lemmy.world/)
- User Rules: (https://legal.lemmy.world/fair-use/)
2. Be kind and friendly.
- Please be kind to others on this community (and also in general), and remember that for many people Perchance is their first experience with coding. We have members for whom English is not their first language, so please be take that into account too :)
3. Be thankful to those who try to help you.
- If you ask a question and someone has made a effort to help you out, please remember to be thankful! Even if they don't manage to help you solve your problem - remember that they're spending time out of their day to try to help a stranger :)
4. Only post about stuff related to perchance.
- Please only post about perchance related stuff like generators on it, bugs, and the site.
5. Refrain from requesting Prompts for the AI Tools.
- We would like to ask to refrain from posting here needing help specifically with prompting/achieving certain results with the AI plugins (
text-to-image-plugin
andai-text-plugin
) e.g. "What is the good prompt for X?", "How to achieve X with Y generator?" - See Perchance AI FAQ for FAQ about the AI tools.
- You can ask for help with prompting at the 'sister' community Casual Perchance, which is for more casual discussions.
- We will still be helping/answering questions about the plugins as long as it is related to building generators with them.
6. Search through the Community Before Posting.
- Please Search through the Community Posts here (and on Reddit) before posting to see if what you will post has similar post/already been posted.
view the rest of the comments
__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: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 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.