STRING PARSER: Difference between revisions

From AddictHelp
Jump to navigation Jump to search
Kahlan (talk | contribs)
New page: 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 c...
 
Kahlan (talk | contribs)
No edit summary
Line 47: Line 47:
========================
========================


As mentioned, all the choices in the examples above have an equal chance
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
of being displayed - they are all possible choices and then one of the
possible choices is picked randomly.
possible choices is picked randomly.


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


? - Conditional Expression - is follwed by a C-like expression which
? - Conditional Expression - is follwed by a C-like expression which
    is evaluated as true (non 0 ) or false ( 0 )
    is evaluated as true (non 0 ) or false ( 0 )
    The following operators can be used in the expression, and act
    The following operators can be used in the expression, and act
    exactly like their C counterparts:
    exactly like their C counterparts:
    ==, !=, !, <, >, <=, >=, &&, ||, -, *, +, /, (, )
    ==, !=, !, <, >, <=, >=, &&, ||, -, *, +, /, (, )


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


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


    In this case, if the char's intelligence were less than 10, s/he'd get
    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.
    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
    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,
    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
    the second message would still be a possibility.  If a text-choice has
    no expression before it, it will always be a possibility.
    no expression before it, it will always be a possibility.


     Note also that the expression ends with a :, and that the spacing  
     Note also that the expression ends with a :, and that the spacing  
Line 83: Line 83:
     as you can in C
     as you can in C


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


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


     You can also do the following:
     You can also do the following:
    [ ? int : Text_choice.....]
    [ ? int : Text_choice.....]
    This will be a possibility, as long as int is non-zero
    This will be a possibility, as long as int is non-zero


     Syntax errors, overflows, etc.
     Syntax errors, overflows, etc.
    If you try to go beyond the 32767 or -32767, the value is simply  
    If you try to go beyond the 32767 or -32767, the value is simply  
    stopped at the max - therefore 32767 *20 would equal 32767
    stopped at the max - therefore 32767 *20 would equal 32767
    Dividing by zero will result in zero (rather than infinity :) )
    Dividing by zero will result in zero (rather than infinity :) )
    If you have a syntax-error,
    If you have a syntax-error,
    eg. [? 3 ++ 3: Text_choice....]
    eg. [? 3 ++ 3: Text_choice....]
    then that choice will simply default to false and be a possibility.
    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  
>  # m,n - Evaluates to true if the mth choice set chose to display the  
     nth choice.
     nth choice.


e.g. [Many\An] [#1,2:egg\#1,1:eggs] [#1,2:is\#1,1:are] [laying\buried] here.
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  
This way, if Many is randomly picked, eggs, and are will automatically be  
picked.  Likewise, egg, and is will be picked if An is.
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
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.
earlier choice-set based upon what will be picked in a later one.


e.g. [#2,2:Many\#2,1:An] [egg\eggs]
e.g. [#2,2:Many\#2,1:An] [egg\eggs]
This will result in an error.
This will result in an error.


! - Makes the choice-text a possiblity only if no other choices in the
! - Makes the choice-text a possiblity only if no other choices in the
    choice set are possibilities.
    choice set are possibilities.


As mentioned eariler,
As mentioned eariler,
[?int < 10 :Text_choice1\Text_choice2]
[?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 !


doesn't guarantee to print out Text_Choice1 if int < 10; it guarantees NOT
[?int <10:Text_choice1\!:Text_choice2]
to print Text_Choice1 if int >= 10, but if int < 10, there is a 50% that
Then if int < 10, only Text_choice1 will print.
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:
You can also combine these three different evaluators all you want:


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


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


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

Revision as of 19:45, 19 November 2008

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 follwed 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 possiblity only if no other choices in the
    choice set are possibilities.
As mentioned eariler,
[?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 parsable 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