Hi everyone, just getting to grips with Perchance, love the functionality and simplicity. Not a coder, so coming at this as a newbie.
I’m trying to build a dental patient generator for students to practice diagnosis on. I’ve got a simple version working: https://perchance.org/91ba5azokj But I need some condition-based logic so that the relevant variables only apply to the front or back tooth.
Front tooth If UL1 or LR2, it can link with:
• Mesial, Distal, Buccal or Lingual/Palatal • Composite or Glass Ionomer Cement • Any medical history • Any presenting complaint • Any ‘other’ item
Back tooth If UR6, UR4, LL6 or LR7, it can link with:
• MO, DO, MOD • Amalgam or Composite • Any medical history • Any presenting complaint • Any ‘other’ item
I can’t see how to build this with the plug-ins I’ve explored and having read the tutorials (a few times!). Any tips? I’ve got the information for the medical history, presenting complaints and other items to add later.
Here is a modified generator.
So first, we store the selection from the
tooth
list in a variable calledx
. We use.evaluateItem
on thetooth
so we can have the ‘string’ / evaluated form of the item i.e. a text without the perchance syntax.What we have on the
surface
list is what we call Dynamic Odds. Basically, it modifies the odds of the items in the list depending on the ‘condition’ that is on the odds. Essentially a ‘If/Else’ statement to control the odds/probability of an item to be chosen.In this case, we use the value on the variable
x
and check if it ‘includes’ a certain string, which would be your conditions ‘UL1’ and ‘LR2’.On the first three items:
surface Mesio-occlusal (MO) ^[!x.includes('UL1') && !x.includes('LR2')] Disto-occlusal (DO)^[!x.includes('UL1') && !x.includes('LR2')] Mesio-occlusal-distal (MOD)^[!x.includes('UL1') && !x.includes('LR2')] ...
We use the native JavaScript method
.includes()
to check if the value onx
includes a certain string, in this case it is checking for ‘UL1’ and ‘LR2’. However, we are using the!
or ‘NOT’ notation to invert it, so we are checking if the string doesn’t contain the following strings. We then use theor ‘AND’ notation to only return a ‘true’ statement if and only if BOTH conditions are true.
In this case, it would be true if
x
doesn’t includeUL1
ANDLR2
. Which means other thanUL1
andLR2
, the engine wouldn’t be able to ‘pick’ those first three items unlessx
doesn’t includesUL1
andLR2
On the last items:
surface ... Buccal (B)^[x.includes('UL1') || x.includes('LR2')] Labial (L)^[x.includes('UL1') || x.includes('LR2')] Palatal (P)^[x.includes('UL1') || x.includes('LR2')] Distal (D)^[x.includes('UL1') || x.includes('LR2')] Mesial (M)^[x.includes('UL1') || x.includes('LR2')] ...
We do the opposite, we only allow the engine to select those items ONLY if
x
hasUL1
ORLR2
. The||
is the OR operator in which it would return ‘true’ if only one of the items are ‘true’.I also added on the generator my ‘debugging’ utilities in which you can see the how the ‘odds’ are on the items depending on the value on
x
.Here are some resources to read:
Thank you VioneT and allo for taking the time to help me with this. Very much appreciated, and for the supporting resources.
https://perchance.org/hmz8js3o3v
i’d say Vione’s is basically ‘the right way’ and i made a noob one, but maybe my noob one will help :)
- i had it split at the top in to back teeth and front teeth instead of all teeth together.
- then for the variables that apply to one or the other, i split them in to: backteethsurfaces and frontteethsurfaces
it isn’t really condition based logic like in real time like you are implying and vioneT answered. It’s more just splitting your types of things in to a box for each type of thing. Also I noticed you had all your lists referenced only in output, but you can reference a list in a list as you see i did with how tooth then is either a back or front tooth and then back tooth has it’s lists and front tooth has it’s lists and they are different from each other. edit: touch edit to see what i did. idk teeth so i made up my own surface types and such.