[Bug/Suggestion] `create-instance-plugin` Doesn't Fix Deep Properties with Same Level Lists

Suppose we have the following list:


<span style="color:#323232;">createInstance = {import:create-instance-plugin}
</span><span style="color:#323232;">
</span><span style="color:#323232;">person
</span><span style="color:#323232;">  name = [this.nameList]
</span><span style="color:#323232;">  nameList
</span><span style="color:#323232;">    Salman
</span><span style="color:#323232;">    Manny
</span><span style="color:#323232;">    Rhian
</span><span style="color:#323232;">  age = {31-49}
</span><span style="color:#323232;">  child = [this.child_obj]
</span><span style="color:#323232;">  child_obj
</span><span style="color:#323232;">    name = [this.nameList]
</span><span style="color:#323232;">    nameList
</span><span style="color:#323232;">      Anne
</span><span style="color:#323232;">      Arram
</span><span style="color:#323232;">      Amelia
</span><span style="color:#323232;">    age = {3-17}
</span>

If we output:


<span style="color:#323232;">[p = createInstance(person, "deep"), p.name] [p.age] [p.name] [p.age]
</span>

We can see that it has fixed the name and the age property on the instance. However, if we output:


<span style="color:#323232;">[p = createInstance(person, "deep"), p.child.name] [p.child.age] [p.child.name] [p.child.age]
</span>

It would throw undefined. Now looking at similar list:


<span style="color:#323232;">person
</span><span style="color:#323232;">  name = {Salman|Manny|Rhian}
</span><span style="color:#323232;">  age = {31-49}
</span><span style="color:#323232;">  child = [this.child_obj]
</span><span style="color:#323232;">  child_obj
</span><span style="color:#323232;">    name = {Anne|Arram|Amelia}
</span><span style="color:#323232;">    age = {3-17}
</span><span style="color:#323232;">
</span><span style="color:#323232;">output
</span><span style="color:#323232;">  [p = createInstance(person, "deep"), p.child.name] [p.child.age] [p.child.name] [p.child.age]
</span>

This would have the values fixed and working.

Looking at the code of the create-instance-plugin, it would only allow the ‘deep’ fixing of properties if there isn’t any items/lists in it. What that means is the following:


<span style="color:#323232;">child_obj
</span><span style="color:#323232;">  name = [this.nameList]
</span><span style="color:#323232;">  nameList
</span><span style="color:#323232;">    Anne
</span><span style="color:#323232;">    Arram
</span><span style="color:#323232;">    Amelia
</span><span style="color:#323232;">  age = {3-17}
</span>

This object/list, has a list ( nameList) within it as well as properties (name and age), while:


<span style="color:#323232;">child_obj
</span><span style="color:#323232;">  name = {Anne|Arram|Amelia}
</span><span style="color:#323232;">  age = {3-17}
</span>

Only has properties. and based on Line 22 of the create-instance-plugin:


<span style="font-weight:bold;color:#a71d5d;">...
</span><span style="color:#323232;">} </span><span style="font-weight:bold;color:#a71d5d;">else if</span><span style="color:#323232;">(propValue.getPropertyKeys </span><span style="font-weight:bold;color:#a71d5d;">&& </span><span style="color:#323232;">propValue.getPropertyKeys.length </span><span style="font-weight:bold;color:#a71d5d;">> </span><span style="color:#0086b3;">0 </span><span style="font-weight:bold;color:#a71d5d;">&& </span><span style="color:#323232;">propValue.getLength </span><span style="font-weight:bold;color:#a71d5d;">=== </span><span style="color:#0086b3;">0</span><span style="color:#323232;">) {
</span><span style="font-weight:bold;color:#a71d5d;">...
</span>

If the list to be fixed has a list within it other than the properties i.e. propValue.getLength is not zero, then it wouldn’t fix the properties within it.

The first child_obj has a nameList with it, and upon calling propValue.getLength it would have 1 while the second child_obj will return a propValue.getLength of 0 since it doesn’t have any lists.

Thus, the solution for the problem is just removing the propValue.getLength === 0 check OR create another check without it.


TLDR; propValue.getLength === 0 at Line 22 of the create-instance-plugin can be removed to allow properties that rely on same level lists to be fixed. Here is the demo of the problem with a ‘remixed’ create instance plugin with the fix.

perchance, (edited )

Thanks for this! I was just looking into it, and I noticed this comment at the bottom of the code in create-instance-plugin:


<span style="font-style:italic;color:#969896;">// Important counter-intuitive thing to take note of: https://www.reddit.com/r/perchance/comments/nh31xq/the_best_hack_for_methods_in_list_instances/gz0rebt
</span><span style="font-style:italic;color:#969896;">// the "deep" option of the createInstance plugin is kinda messed up. I should warn people that the [child] list should ONLY have properties - no sub-lists. That basically solves everything, but it's a bit annoying in many cases. Ideally I'd have only called selectOne on a list if it has no properties (i.e. with equals sign). If it has properties it should be treated just as part of the hierarchical blueprint, and those sub-items should get fixed, rather than having selectOne called on it.
</span><span style="font-style:italic;color:#969896;">// I basically need a new plugin. createInstance2 = {import:create-instance-2-plugin}
</span><span style="font-style:italic;color:#969896;">// That's the ideal solution here.
</span><span style="font-style:italic;color:#969896;">// https://perchance.org/hiad2okk9w
</span>

Which, IIUC, is exactly what you’re talking about here.

So I was reluctant to make that change back then due to potentially breaking peoples’ generators. With the number of generators that use this, it’s possible that people are “using” this ~bug. On the other hand, it is hard to see why someone would use “deep”, and not want the deep properties fixed. It does seem like the current behavior would be causing more pain to people trying to use it right now than the pain caused by breaking old generators that actually wanted random sub-sub-properties even though they used the “deep” mode.

I.e. seems like the generator would already have to be “buggy” for this change to cause any issues. Hmm. Yeah, on balance this does seem like it should be categorized as a bug, and fixed. The lower-level lists should be treated just like the upper-level lists - intuitively, that’s exactly what is meant by “deep”. Thoughts?

perchance, (edited )

Hmm. Thinking about this more, I’m really reluctant to do this in case it breaks old generators - even though it’s hard to imagine someone relying on this ‘bug’ on purpose. So what I might do instead is expose a new window.generatorLastEditTime variable (like window.generatorName and window.generatorPublicId), and only enable the new behavior if the last save time of the generator is newer than today. So if people are still actively working on their generator now then they’ll get the new behavior, and if it does break something they’ll be able to notice and fix it. But for old generators, they get to keep the old behavior until the author comes back to it and makes an edit.

I think that strikes a good balance here. What do you think?

VioneT, (edited )
@VioneT@lemmy.world avatar

I think that is a nice idea. I think, if the generator is not updated recently, maybe create an alert() to alert the generator owner that it might give bugs if they update their generator,? also to let them know that a change has been made and it ‘might’ break their generator if they update.

EDIT: I think that it wouldn’t break much since with the current create-instance-plugin they wouldn’t actually be able to use lists in deeper instances since it would automatically return undefined, which would mean the users that tried to do what I did, didn’t do it since it throws undefined in their code. So, I would hope that it wouldn’t break generators much.

perchance, (edited )

Hmm, I think I misunderstood some stuff with my earlier comments. With the caveat that this is frying my brain a little, I think there are cases that this change would break - e.g. perchance.org/bm1vp6py5a#edit Try swapping the plugin import to see the behavior change.

If it turns out it isn’t really possible to fix this issue, then it may be time for me to make a new plugin which fixes this issue and some others, and perhaps introduces some handy features that people tend to need. Let me know if you have any requests in that department - e.g. everything gets fixed by default, but if a property name begins with * (or something), like *foo, then character.foo would be a random property, instead of being fixed/resolved. And another thing I think is to call evaluateItem after selectOne if the selected item has no children. Not sure though - would definitely need feedback on this from people who use the plugin extensively.

Another alternative is to just add an extra “mode” to create-instance-plugin (like the existing “deep” one), which fixes all the issues and makes everything intuitive, but that might make it a bit more complicated and cumbersome, since the behavior would vary so much, which could be confusing to newbies.

VioneT, (edited )
@VioneT@lemmy.world avatar

Okay, might be too crazy now but, if the list has a list propValue.getLength > 0, we can do a .selectOne to it, then re-apply the previous properties to it. Meaning, it would have one ‘list’ value, but it would still have the previous properties.

You can check the code here: perchance.org/hxoknecflu

But if that might break more generators, then probably a new instance plugin might be good XDDDDD.

Edit: it might still be breaking generators, since if the item that was .selectOneed is a list, then it would still randomize and not be fixed: See the [p.child.testing] in this generator: perchance.org/vnm320e3k6#edit

VioneT,
@VioneT@lemmy.world avatar

@perchance pinging dev

  • All
  • Subscribed
  • Moderated
  • Favorites
  • perchance@lemmy.world
  • DreamBathrooms
  • everett
  • osvaldo12
  • magazineikmin
  • thenastyranch
  • rosin
  • normalnudes
  • Youngstown
  • Durango
  • slotface
  • ngwrru68w68
  • kavyap
  • mdbf
  • InstantRegret
  • JUstTest
  • ethstaker
  • GTA5RPClips
  • tacticalgear
  • Leos
  • anitta
  • modclub
  • khanakhh
  • cubers
  • cisconetworking
  • megavids
  • provamag3
  • tester
  • lostlight
  • All magazines