Prog Section 2

From Immwiki
Revision as of 23:18, 9 May 2011 by Telelion (Talk | contribs)

Jump to: navigation, search

Variables

"Moods are for cattle and loveplay, not for fighting!"

-- Gurney Halleck, Dune

More often than not, you will want to reference the persons, mobs, or things associated with progs. Furthermore, you will not, a priori, know the names of the persons, mobs, or items which trigger or are acted on by the progs. The solution to this is a system of variables.

Variable Syntax:

1. The $ symbol

The $ symbol prefaces every variable. It is equivalent to saying "the value which is
stored in". So, let’s suppose we have a variable called n. n’s current value is 'Jolinn'
(it’s a character value). Every time the prog sees $n, the prog engine interprets that as
'the value stored in n', which means that every time the prog sees $n, it reads it as 'Jolinn'.
Additionally, it is possible to have multiple '$' characters iterated, defined recursively.
I.e., suppose we have two variables, 3 and 4.
If
$4 == 3
and
$3 == 5000
then $$4 == $(3) == $3 == 5000

2. List of variables

The following table provides a summary of the most basic variables.
a:                                    A: 
b: short desc. of obj carrier         B: his/her of obj carrier
c:                                    C: 
d:                                    D: 
e: he/she of actor                    E: he/she of focus 
f: name of focused on                 F: short desc. of focused on 
f0: name of focus 0.                  F0: short desc. of focus 0. 
f1: name of focus 1.                  F1: short desc. of focus 1. 
g:                                    G: 
h: Amount of damage done by a hit     H:
   (see hit prog)
i: name of mob                        I: short desc. of mob 
j: he/she of mob                      J: he/she of random 
k: him/her of mob                     K: him/her of random 
l: his/her of mob                     L: his/her of random 
m: him/her of actor                   M: him/her of focus
                                      M0: him/her of focus slot 0
                                      M1: him/her of focus slot 1 
n: name of actor                      N: short desc. of actor 
o: if on mob: name of obj             O: if on a mob: short desc. of obj 
   if on on an object: name of owner  O: if on an object: short desc. of owner 
p:                                    P: 
q:                                    Q: 
r: name of random                     R: short desc. of random 
s: his/her of actor                   S: his/her of focus slot
                                      S0: his/her of focus slot 0
                                      S1: his/her of focus slot 1 
t: name of vict                       T: short desc. of vict 
u:                                    U: 
v: loop value check:                  V:
 v1: loop value, depth 1
 v2: loop value, depth 2
 vn: loop value, depth n,
     n a positive integer >= 1
w:                                    W: 
x: text of command (if appli.)        X: $x, with the first word excluded 
y: argument lookup (punc.)            Y: argument lookup (punc. sensitive)
y1: First word of argument            Y1: First word of argument
y2: Second word of argument           Y2: Second word of argument
yn: nth word of argument              Yn: nth word of argument 
z: value from mpremember              Z: Long desc. of actor

1,2,3,4,5,6,7,8,9: Value stored in corresponding mobile integer memory value

Now, this is all a bit much to digest at once, but let’s define what some of
these terms mean:
The actor of a prog is the entity which triggers the prog.
  Ex:
  greet_prog 100
  say Hello, $n
And Jolinn enters the room, the room will see:
  The mob says, ‘Hello, Jolinn’
This is because Jolinn is the person who triggers the prog.
The mobile of the prog is the entity which has the prog, be it a mob or
object.
  Ex:
  greet_prog 100
  say This prog is on $I.
Let’s suppose this mob were on ‘a hen’. Whenever someone entered the room, they
would see:
  A hen says, ‘This prog is on a hen.’Notice that here we use the capital version
  of the variable, $I, since the name of a mob is not really what we want to say to
  the room (its name might be hen yellow feathered loud demon -- not something you 
  want to echo to the room!).
The random prog variable selects a random target in the room. The random variable,
once invoked within a given prog, remains the same for the duration of the prog. (So, if
you have two instances of $r in a prog, they will both refer to the same (random) entity.)
The random variable will also never reference the mobile or object on which the prog exists.
  Ex:
  greet_prog 100
  say $r is a random person in the room.
Suppose that this prog is on a mob in a room with Jolinn, Iandir, and Aeolis. If Arkhural
enters the room, the mob might do any one of the following.
  The mob says, ‘Jolinn is a random person in the room.’
  The mob says, ‘Iandir is a random person in the room.’
  The mob says, ‘Aeolis is a random person in the room.’
  The mob says, ‘Arkhural is a random person in the room.’
Each of these has an equal probability of occurring.
The victim variable refers to the object of the actor's action. This variable is
less frequently used, but denotes the subject of the actor's ($n) action. Since it is not
valid in every prog type, you should research whether your prog trigger even allows the
use of this variable.
The object variable refers to EITHER:
(i) The object which triggers the prog (if the prog is on a mob)
(ii) The owner of the object (if the prog is on an object)
The focus variable refers to a pc stored in a mobile focus slot. We’ll learn more about
focus slots when we cover mobile memory, but for right now, the key fact is that the
variables which are listed above are how we reference focus slots from within a prog.
The loop variable is a variable used in loops to identify what iteration, or "step" a
loop is currently on. We will discuss this variable more in the section on control structures.
The command text variable is used to reference the text of a given prog’s argument.
Essentially, whenever there is an argument to a prog_trigger which is a player input, $x,
the command text variable, can be used to reference this value.
  Ex: 
  speech_prog p 
  tell $n You just said $x. 
This prog is a prog which triggers on anything spoken, and when it does, it invokes $x.
$x, here, represents the entire line that trigged the prog. So, if this prog were on a mob,
and someone in the room were to say "I hear Jolinn has quite the taste for ethron trollops."
the prog would trigger, and you would see:
  Mob tells you, ‘You just said I hear Jolinn has quite the taste for ethron trollops.’
$x has other, more interesting uses, as we will see later. $X is identical to $x, except that
the first word is stripped. [This functionality is rarely used.]
The argument lookup variable is a variable that allows us to reference the content
of a prog’s argument. Essentially, an argument lookup variable works like this: Suppose we
have the prog trigger speech_prog, which triggers when a certain key word or phrase is said.
So, maybe we’d like the mob to respond to:
  "I want you to threaten <person>" 
with a tell to <person>, telling them, "You’d better watch yourself, <person>!"
Now, we want a speech_prog for this, so we might use:
  speech_prog p I want you to threaten 
But then we’re left with being unable to pass the information about the word after
"threaten", since it’s going to going to be something variable, and therefore not
something you can put in a speech_prog (unless you had a speech prog for every n
letter player name!).
The $y variable is what allows us to reference the arguments of a prog directly.
In general, any place where $yn (where "n" is an integer n >= 1) occurs, the prog
interprets this as "the value of the nth word in the prog argument". As an example,
suppose we had the speech_prog:
  speech_prog p I want you to threaten
  tell $y6 You’d better watch yourself, $y6!
Now, if you were to say aloud, in this room: "I want you to threaten Jolinn", the
mob would tell Jolinn: "You’d better watch yourself, Jolinn!" The reason being:
Jolinn is the sixth entry in the argument, and hence it is referenced by $y6.
By default, $y will strip any punctuation from its argument target. The capital
version, $Y will preserve punctuation (this is rarely needed). The argument lookup
variable has many more uses, as we will see in later sections.

Local Variables

Local variables, unlike the normal $0-$9 mobvalues, persist only for the duration
of the prog in which they're created. They can hold numeric or string values.
They are prefixed with a % (as opposed to $ for mobvalues) and can be given any
alphanumeric name that is not a number.
They are otherwise used just like mobvalues, and work with:
mpvalueset mpvaluerand
mpvalueup (*) mpmath
mpvaluedown (*) mpgetroomvnum
and with
if (mob/obj/room)value
NOTE! You no longer (as of June 2003) need to use "mobvalue/objvalue/roomvalue" for
any of your if checks. Just "value" should suffice.
Here is an example of the local variables in action:
mpvalueset gstr Hello, I am a local variable.
mpecho %gstr
mpvaluerand apples 1 3
mpecho I have %apples apples.
if value(apples) == 3
  mpecho Wow, that's a lot of apples!
endif
mpmath apples %apples * 2
mpecho I now have %apples apples.  That's twice as many as before!
I'm sure you can figure out what the above would do.