Difference between revisions of "String Parsing"

From Flexible Survival
Jump to: navigation, search
m
(Limits)
Line 159: Line 159:
 
String Parsing ''cannot'':
 
String Parsing ''cannot'':
 
* Compare two variables. (If cocks > cunts)
 
* Compare two variables. (If cocks > cunts)
 +
* Test for effects. (DamResist)
 +
* Test for combat.
 +
* Message other players or provide other output.
 
* Do math. (1 + 2)
 
* Do math. (1 + 2)
  

Revision as of 17:05, 4 January 2012


String Parsing (SP) refers to some of the underlying guts of the MUD. You can use it to liven up your creature submissions, rooms, and even your own description. While it's a bit limited in power compared to other languages, it's easy to read and learn. If you're new to programming, it's recommended you use notepad to work in. This lets you save your files localy in case of a disconnect, and avoids weird formatting issues that sometimes pop up in Word. If you're going to be using SP heavily, look for a text editor Notepad++ (Windows), Fraise (Mac), or VI,eMacs,Etc (Linux).

Basic Syntax

Formatting

Everything in SP is contained in brackets []. Though SP is supposedly case insensitive, it's recommended you use only lowercase.

There should be no spaces after the leading bracket or before the trailing bracket.

[like this]
[ not like this ]

Line breaks are bad. Avoid them within brackets, and within [if...][end if] sections.

This is bad.

Hi [player]![if [player] is male]
I'm a
boy![end if]

This is good.

Hi! [player]!
[if [player] is male]I'm a boy![end if]

Variables

SP can retrieve, test, and display certain pieces of information about characters.

Targets

A Target refers to a specific character. Targets must be enclosed in their own set of brackets. A [target] by itself will return the target's name.

Hi [player]!

returns

Hi Nuku!

Valid Targets:

[player] - Name of character the description is on.
[looker] - Name of the character viewing the description.
[loser] - The loser of a fight. (For victory/defeat messages.)
[victor] - The winner of a fight (For Victory/defeat message.)
[infected] - Returns target of infection (Creature infection message only. May not be valid still.)

Pronouns

These will display the correct gender of the pronoun according to the target.

Use:

[pronoun of [target]]
Example: You see an employee badge hanging from [%p of [player]] coat.

Available Pronouns (Examples are not valid code. They are only demonstrating where

%p/%P for possessive pronouns (his/her/its <item>, His/Her/Hir/Its <item>)
Example: Who's book is it? It's %p book.
%a/%A for absolute possessive pronouns (his/hers/hirs/its, His/Hers/Hirs/Its)
Example: Who's book is it? It's %a.
%s/%S for subjective pronouns (he/she/shi/it, He/She/Shi/It)
Example: %S got the book.
%o/%O for objective pronouns (him/her/hir/it, Him/Her/Hir/It)
Example: The book fell on %o.
%r/%R for reflexive pronouns (himself/herself/hirself/itself,Himself/Herself/hirself/Itself)
Example: Chris did it all by %r.
%n/%N for the player's name. (Also can just use [target] by itself.)
The shopkeeper's name is %n .

Stats

You can use SP to retrieve information about a target using [stat stat of [target]]

HP - Returns current raw HP.

Body Parts

You can retrieve the numerical value of body parts with [stat part of [target]]

Breasts - Number of breasts
Breast Size - Returned as a numerical value (1, 2, 3) not cup size.
Cocks - Number of Cocks
Cock Length
Cock Width - Ball Size
Cunts - Number of counts
Cunt Length - Depth of Cunt

(Not sure how Modest Appearance perk affects this.)

Mutations

Using [stat mutation/part of [target] will retrieve the mutation present in that location.

mutation/skin - returns skin mutation
mutation/head - returns head mutation
mutation/arms - returns arms mutation
mutation/torso - returns torso mutation
mutation/cock - returns groin mutation
mutation/legs - returns legs mutation

Other Values

These values do not need to be proceeded by 'stat'. use "value of [target]".

hp - shows the percentage of total HP. A target at 50% health will return '50'. (To get raw HP, use '[stat HP of [target]') Will return 0 or 100 after mentoring up/down until the next reg 'tick'.
pregnant - returns pregnancy value as 0 or 1 (pregnant).
[skin] -- returns the primary user's skin, primary user can be tricky at times, safest to use in descs and transformations. (better to use mutation/skin)
freecred - returns target's freecred balance
level - returns target's true level
mentor - returns target's mentored level

Flags

You can check for certain features in a target using flags. [if flag is present in [target]]You have something that's flag.[end if] For a list of available flags to check for, see the flag list.

Functions

SP provides a few simple functions for data processing.

Tests

If-Then tests are formatted as [if X]item 1[otherwise]item 2[end if].
You do not need to include [otherwise] but you must finish with [end if]
To test multiple items in one check use [if a and b and c], Not [if a and if b and if c]
You can nest if-thens, but remember your [end if]s.
Comparisons
[if X is Y] or [if X is not Y]
[if stat (stat name) of (person name) = (number)]
[if stat (stat name) of (person name) > (number)]
[if stat (stat name) of (person name) < (number)] -- Do stat comparisons!
test for a power [if POWER NAME is owned by TARGET]
Test gender
[if TARGET is male] - Does TARGET have a cock?
[if TARGET is female] - Does TARGET have a pussy?
[if TARGET is not male] and [if TARGET is not female] - Testing for absence of cock/pussy
[if TARGET is neuter] - Is TARGET Neuter (same as above, but shorter)
[if TARGET is not male and TARGET is not female] - Combining tests. Only a neuter will pass this.
[if TARGET is male and TARGET is female] - Combining tests. Only a herm will pass this.
[if TARGET is herm] - Is TARGET a herm? (same as above, but shorter)
Test ferility
[if TARGET is fertile] - Non-females cannot be fertile and will always fail this test.

Randoms

[one of]X[or]Y[or]Z[at random]. Do NOT nest randoms.

Nesting

You may nest [if..][end if] tests. Do NOT nest [one of]...[at random] sections.

[if [player] is male]I'm a boy[if [player] is female] and a girl[end if]![end if]

Do NOT use [else].

Colors

You can add color to your text. (Also works with @emit command.)

Surround the color name in carets (for example, ^red^), then return to normal with ^normal^
Valid colors: Red, blue, green, cyan, yellow, brown, black, white, gray/grey, possibly others. Use 'colors' command to see full list.
You can also use ^bold^, ^italics^, ^underline^, and yes, even ^blink^.

Advanced Code

These will not work in personal or room descriptions. Mostly for use in creature creation and other NPC scripts.

Functions

[increase the (stat) of (person name) by (number)] Modify stats, negative numbers are cool. Whole numbers only.
[impregnate (person name) with (person name)] -- Causes a chance for babies. The first is the mother. Both need proper parts.
[end] -- Used in defeat# and victory# to end the processing in that block if [end] remains after displaying that block.

Targets

[here] -- used to identify the room (not its name, its DB ref)

Limits

String Parsing cannot:

  • Compare two variables. (If cocks > cunts)
  • Test for effects. (DamResist)
  • Test for combat.
  • Message other players or provide other output.
  • Do math. (1 + 2)

Example Code

NPC Name Tracking

By Damaged: You want to say, have a particular name hang about, on the player, so that once they have given in

[if stat Fox/Name of player = 0]"Oh, have we not met? My name is [one of]Lilly[increase the Fox/Name of player by 1][or]Michelle[increase the Fox/Name of player by 2][or]Jenny[increase the Fox/Name of player by 3][at random], and I am going to fuck you nine ways from tuesday!"[otherwise]"Oh, [player]!" [if stat Fox/Name of player = 1]Lilly[end if][if stat Fox/Name of player = 2]Michelle[end if][if stat Fox/Name of player = 3]Jenny[end if] says, "Its tuesday again!"[end if]


Set player color

by Damaged:

str /Infection/Goo Girl/Skin/Transform:A ripple of tingles rushes through your entire body as you sink towards the ground, then rise again, wobbling along the way. A glance at a hand shows that you can see right through your now [set the Goo Girl/texture of player to [one of]jellied[or]gelatine like[or]translucent[at random]] [set the Goo Girl/color of player to [one of]blue[or]red[or]purple[at random]]


Deprecated Code

These functions and items do not work anymore, but are listed for legacy purposes.

[infect (person name) with (infection name) at (number)] -- has a (number)% chance of infecting the named person with the named infection.

Resources

Damage's Original 'Guides' post

Help on String Parsing