STRING PARSER

From AddictHelp
Jump to navigation Jump to search

DEPRECATED


The string parser is being replaced with a parser that is driven by https://github.com/pantor/inja, and will be documented in the wiki.


In any the description or name of any room that has the parser flag, you can setup multiple choices of what text will be output to screen. Simply put your choices in the format:

[text choice 1\text choice 2\text choice 3]

The text choice can be any length - from 1 letter to many words.

e.g.  [A\Several\One hundred]

could output the text - 'A', 'Several', or 'One hundred' - in this instance, each choice of the three has an equal chance of being output - you can also set up conditional expressions before each choice to determine which choice gets picked (see Conditional Expressions below).

You can have as many of these choice-sets as you like

e.g. [Many\Few\An] [eggs\egg] are [laying\buried] here.
Could become several possibilities:
Many eggs are laying here.
Few eggs are laying here.
An eggs are laying here.
Many egg are buried here.
etc.

Note that you will generally want a space between each of the choice sets,

e.g.
[Many\Few\An][eggs\egg]
Would come out as:
Manyeggs
Fewegg
etc.


Additionally, you probably don't want to use spaces between the choice seperators '\', or '[', ']' and the choice-text in the choice sets.

eg.
[ Many \ Few \ An ]

All the words will have extra spaces before and after them.

Conditional Expressions

As mentioned, all the choices in the examples above have an equal chance of being displayed - they are all possible choices and then one of the possible choices is picked randomly.

You can narrow down the number of possible choices by inserting an expression before the text. There are three types, identified by the symbol they start with: Note that they all end with a ':'

? - Conditional Expression - is followed by a C-like expression which is evaluated as true (non 0 ) or false ( 0 ) The following operators can be used in the expression, and act exactly like their C counterparts:

==, !=, !, <, >, <=, >=, &&, ||, -, *, +, /, (, )

Constant numbers from -32767 to 32767 can also be used (no decimals) as well as certain pre-set variables. Note - you will have to check with Isaiah as to what variables will be available - many will probably refer to a character's attributes, such as str, wis, dex, int.

    e.g.
    [? int<10:You see big rocks.\? int >=10:You notice several varieties
    of igneous rock here.]

In this case, if the char's intelligence were less than 10, s/he'd get the first message, otherwise, the second message will be displayed. Note that if the ? int >=10: were admitted, and if the char's int was less than 10, the first message wouldn't be guaranteed to be displayed, the second message would still be a possibility. If a text-choice has no expression before it, it will always be a possibility.

Note also that the expression ends with a :, and that the spacing between the ? and the : doesn't matter. You shouldn't leave a space between the : and the first letter of the text-choice, however, as it will result in an extra space. You can make the expression as involved as you can in C.

    e.g.  [? int>(wis/2)+3 || (dex > 5 && time != 12 ): Text_choice....]

is perfectly valid - the operator precedence is exactly the same as in C.

You can also do the following:

    [ ? int : Text_choice.....]

This will be a possibility, as long as int is non-zero

Syntax errors, overflows, etc.

If you try to go beyond the 32767 or -32767, the value is simply stopped at the max - therefore 32767 *20 would equal 32767 Dividing by zero will result in zero (rather than infinity :) ) If you have a syntax-error,

    eg. [? 3 ++ 3: Text_choice....]

then that choice will simply default to false and be a possibility.

>   # m,n - Evaluates to true if the mth choice set chose to display the 
   nth choice.
e.g. [Many\An] [#1,2:egg\#1,1:eggs] [#1,2:is\#1,1:are] [laying\buried] here.

This way, if Many is randomly picked, eggs, and are will automatically be picked. Likewise, egg, and is will be picked if An is.

Note: You can only use this in a backward manner, you cannot pick from an earlier choice-set based upon what will be picked in a later one.

e.g. [#2,2:Many\#2,1:An] [egg\eggs]
This will result in an error.
! - Makes the choice-text a possibility only if no other choices in the
    choice set are possibilities.

As mentioned earlier,

[?int < 10 :Text_choice1\Text_choice2]

doesn't guarantee to print out Text_Choice1 if int < 10; it guarantees NOT to print Text_Choice1 if int >= 10, but if int < 10, there is a 50% that Text_choice2 will print, however, if we use the !

[?int <10:Text_choice1\!:Text_choice2]

Then if int < 10, only Text_choice1 will print.

You can also combine these three different evaluators all you want:

e.g. [? dex < 12:Text_choice1\!:Text_choice2] [#1,2:Text_choice1\Text3]

The following items are parse-able right now, with more to come. If you would like a variable added, just ask Brazil.

str
int
dex
wis
con
cha
time (mud time)
day
night
align
sorcerer
cleric
thief
warrior
necromancer
wizard
paladin
antipaladin
druid
dwarf
elf