-
Notifications
You must be signed in to change notification settings - Fork 14
10. Random line selection basic mechanism and priorities
Let's suppose we have these lines in the same InteractionDef:
<li>r_logentry->I hate mechanoids!</li>
<li>r_logentry->I think I know what technical failure doomed our ship.</li>
<li>r_logentry->I think cooperation is the key for success here!</li>
<li>r_logentry->I really enjoy waking up early in the morning.</li>
The code will evaluate them one by one to check if they are valid sentences or not. In our case, since none of them has any condition, all of them are considered valid.
So we have 4 options, but only one will be selected in the end - the one that the pawn will actually speak. How is this choice made?
In the case above, the choice is completely random: each option has 1 in 4 chances to be chosen.
How can I change this? Well, first of all you can condition your lines. Consider this code:
<li>r_logentry->I hate mechanoids!</li>
<li>r_logentry(INITIATOR_intellectual_level>=10)->I think I know what technical failure doomed our ship.</li>
<li>r_logentry->I think cooperation is the key for success here!</li>
<li>r_logentry(INITIATOR_trait==quick sleeper)->I really enjoy waking up early in the morning.</li>
As earlier, each line is evaluated - but this time some of them might not satisfy the conditions. Let's suppose our initiator pawn has a "quick sleeper" trait, but has a zero intellectual skill level. If this is the case, the 2nd line will be ignored. The code will just consider lines 1, 3 and 4. After this initial check, it randomly choses between these 3 options - and the chosen one is spoken out.
So, in the example above, a highly intellectual, quick sleeper pawn could speak any one of those four lines (with the same chance) - whereas a highly intellectual pawn with no quick sleeper trait would only speak one of the first three lines.
Let's suppose now that for some reason this pawn - if capable - should always comment "I think I know what technical failure doomed our ship", avoiding other lines.
To implement this, we can rely on the priority mechanism:
<li>r_logentry->I hate mechanoids!</li>
<li>r_logentry(INITIATOR_intellectual_level>=10,priority=1)->I think I know what technical failure doomed our ship.</li>
<li>r_logentry->I think cooperation is the key for success here!</li>
<li>r_logentry(INITIATOR_trait==quick sleeper)->I really enjoy waking up early in the morning.</li>
Observe the priority=1
part in the second line. In this case, the code evaluates all the lines one by one as usual, but starting from the highest priority line(s). In this case, only one option has the highest priority - the one with the priority=1
part. So, if valid, it will be certainly selected and spoken out - as it's the only option available.
But if the initiator's intellectual level is not high enough, then the "priority=1" sentence will be discarded, and the code will analyze the other "surviving" three sentences (namely 1, 3 and 4). Supposing our pawn is not a quick sleeper, then the possible selection narrows to only options 1 and 3 - and, finally, each one of them will have a 50% chance of being selected and spoken out.
So the priority mechanism is just that: it allows you to give priority to certain sentences, so that they can be evaluated before others. If their condition(s) are not met, then the code evaluates the other sentences, all in priority order. You can have, for instance:
<li>r_logentry->I hate mechanoids!</li>
<li>r_logentry(INITIATOR_intellectual_level>=10,priority=1)->I think I know what technical failure doomed our ship.</li>
<li>r_logentry->I think cooperation is the key for success here!</li>
<li>r_logentry(INITIATOR_trait==quick sleeper,priority=2)->I really enjoy waking up early in the morning.</li>
In this case, the quick sleeper trait is evaluated first (priority=2
). If this check fails, the Intellectual skill level is evaluated (priority=1
). And if this too fails, then only the two surviving unconditioned sentences will be considered and the final spoken sentence will be randomly chosen between them.
Although these examples might seem a bit too specific (or even pointless, maybe?), there is a case where priorities are obviously useful: the NOT operator.