Difference between revisions of "Prog Section 2"

From Immwiki
Jump to: navigation, search
 
m (1. The $ symbol)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= Variables =
+
=Variables=
<i>"Moods are for cattle and loveplay, not for fighting!"</i> -- Gurney Halleck, Dune
+
''"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  
+
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  
+
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  
+
items which trigger or are acted on by the progs. The solution to this is a system of  
variables.  
+
variables.  
  
<b>Variable Syntax:</b>
+
'''Variable Syntax:'''
  
  1. The $ symbol
+
==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
+
:The $ symbol prefaces every non-local variable. It is equivalent to saying "the value which is
    $4 == 3
+
:stored in". So, let’s suppose we have a variable called n. n’s current value is 'Jolinn'
    and
+
:(it’s a character value). Every time the prog sees $n, the prog engine interprets that as
    $3 == 5000
+
:'the value stored in n', which means that every time the prog sees $n, it reads it as 'Jolinn'.
    then $$4 == $(3) == $3 == 5000
+
:Additionally, it is possible to have multiple '$' characters iterated, defined recursively.
 +
:I.e., suppose we have two variables, 3 and 4.
  
   2. List of variables
+
:    If
  The following table provides a summary of the most basic variables.
+
:   $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:  
 
  a:                                    A:  
 
  b: short desc. of obj carrier        B: his/her of obj carrier
 
  b: short desc. of obj carrier        B: his/her of obj carrier
 
  c:                                    C:  
 
  c:                                    C:  
  d:                                   D:  
+
  d: the current line of set data prog  D:  
 
  e: he/she of actor                    E: he/she of focus  
 
  e: he/she of actor                    E: he/she of focus  
 
  f: name of focused on                F: short desc. of focused on  
 
  f: name of focused on                F: short desc. of focused on  
Line 69: Line 71:
 
  z: value from mpremember              Z: Long desc. of actor
 
  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  
+
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  
+
: Now, this is all a bit much to digest at once, but let’s define what some of  
these terms mean:
+
: these terms mean:
  
The <b>actor</b> of a prog is the entity which triggers the prog.
+
: The <b>actor</b> of a prog is the entity which triggers the prog.
 
   
 
   
 
   Ex:
 
   Ex:
Line 81: Line 82:
 
   say Hello, $n
 
   say Hello, $n
  
And Jolinn enters the room, the room will see:
+
: And Jolinn enters the room, the room will see:
  
 
   The mob says, ‘Hello, Jolinn’
 
   The mob says, ‘Hello, Jolinn’
  
This is because Jolinn is the person who triggers the prog.  
+
: This is because Jolinn is the person who triggers the prog.  
  
The <b>mobile</b> of the prog is the entity which has the prog, be it a mob or
+
: The <b>mobile</b> of the prog is the entity which has the prog, be it a mob or
object.
+
: object.
  
 
   Ex:
 
   Ex:
Line 94: Line 95:
 
   say This prog is on $I.
 
   say This prog is on $I.
  
Let’s suppose this mob were on ‘a hen’. Whenever someone entered the room, they
+
: Let’s suppose this mob were on ‘a hen’. Whenever someone entered the room, they
would see:
+
: would see:
  
 
   A hen says, ‘This prog is on a hen.’Notice that here we use the capital version
 
   A hen says, ‘This prog is on a hen.’Notice that here we use the capital version
Line 102: Line 103:
 
   want to echo to the room!).
 
   want to echo to the room!).
  
The <b>random</b> prog variable selects a random target in the room. The random variable,
+
: The <b>random</b> 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  
+
: 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.)  
+
: 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.
+
: The random variable will also never reference the mobile or object on which the prog exists.
  
 
   Ex:
 
   Ex:
Line 111: Line 112:
 
   say $r is a random person in the room.
 
   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
+
: 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.
+
: 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, ‘Jolinn is a random person in the room.’
Line 119: Line 120:
 
   The mob says, ‘Arkhural 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.
+
: Each of these has an equal probability of occurring.
  
The <b>victim</b> variable refers to the object of the actor's action. This variable is  
+
: The <b>victim</b> 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
+
: 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  
+
: valid in every prog type, you should research whether your prog trigger even allows the  
use of this variable.
+
: use of this variable.
  
The <b>object</b> variable refers to EITHER:
+
: The <b>object</b> variable refers to EITHER:
  
(i) The object which triggers the prog (if the prog is on a mob)
+
: (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)
+
: (ii) The owner of the object (if the prog is on an object)
  
The <b>focus</b> variable refers to a pc stored in a mobile focus slot. We’ll learn more about  
+
: The <b>focus</b> 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  
+
: 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.
+
: variables which are listed above are how we reference focus slots from within a prog.
  
The <b>loop</b> variable is a variable used in loops to identify what iteration, or "step" a
+
: The <b>loop</b> 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.
+
: loop is currently on. We will discuss this variable more in the section on control structures.
  
The <b>command text</b> variable is used to reference the text of a given prog’s argument.  
+
: The <b>command text</b> 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,
+
: 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.
+
: the command text variable, can be used to reference this value.
  
 
   Ex:  
 
   Ex:  
Line 146: Line 147:
 
   tell $n You just said $x.  
 
   tell $n You just said $x.  
  
This prog is a prog which triggers on anything spoken, and when it does, it invokes $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,
+
: $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."
+
: 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:
+
: the prog would trigger, and you would see:
  
 
   Mob tells you, ‘You just said I hear Jolinn has quite the taste for ethron trollops.’
 
   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
+
: $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 first word is stripped. [This functionality is rarely used.]
  
The <b>argument lookup</b> variable is a variable that allows us to reference the content  
+
: The <b>argument lookup</b> 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
+
: 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.
+
: 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:
+
: So, maybe we’d like the mob to respond to:
  
 
   "I want you to threaten <person>"  
 
   "I want you to threaten <person>"  
  
with a tell to <person>, telling them, "You’d better watch yourself, <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:
+
: Now, we want a speech_prog for this, so we might use:
  
 
   speech_prog p I want you to threaten  
 
   speech_prog p I want you to threaten  
  
But then we’re left with being unable to pass the information about the word after  
+
: 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
+
: "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  
+
: something you can put in a speech_prog (unless you had a speech prog for every n  
letter player name!).
+
: letter player name!).
  
The $y variable is what allows us to reference the arguments of a prog directly.
+
: 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  
+
: 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,  
+
: interprets this as "the value of the nth word in the prog argument". As an example,  
suppose we had the speech_prog:
+
: suppose we had the speech_prog:
  
 
   speech_prog p I want you to threaten
 
   speech_prog p I want you to threaten
 
   tell $y6 You’d better watch yourself, $y6!
 
   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  
+
: 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:  
+
: 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.
+
: 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  
+
: 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  
+
: version, $Y will preserve punctuation (this is rarely needed). The argument lookup  
variable has many more uses, as we will see in later sections.
+
: variable has many more uses, as we will see in later sections.
  
<b>Local Variables</b>
+
==Local Variables==
  
Local variables, unlike the normal $0-$9 mobvalues, persist only for the duration
+
: 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.  
+
: 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
+
: They are prefixed with a % (as opposed to $ for mobvalues) and can be given any
alphanumeric name that is not a number.
+
: alphanumeric name that is not a number.
  
They are otherwise used just like mobvalues, and work with:
+
: They are otherwise used just like mobvalues, and work with:
 
   
 
   
  mpvalueset        mpvaluerand
+
mpvalueset        mpvaluerand
  mpvalueup (*)    mpmath
+
mpvalueup (*)    mpmath
  mpvaluedown (*)  mpgetroomvnum
+
mpvaluedown (*)  mpgetroomvnum
  
and with
+
: and with
  
if (mob/obj/room)value
+
: if (mob/obj/room)value
  
NOTE!  You no longer (as of June 2003) need to use "mobvalue/objvalue/roomvalue" for
+
: NOTE!  You no longer (as of June 2003) need to use "mobvalue/objvalue/roomvalue" for
any of your if checks.  Just "value" should suffice.
+
: any of your if checks.  Just "value" should suffice.
  
Here is an example of the local variables in action:
+
: Here is an example of the local variables in action:
  
 
  mpvalueset gstr Hello, I am a local variable.
 
  mpvalueset gstr Hello, I am a local variable.
Line 222: Line 223:
 
  mpecho I now have %apples apples.  That's twice as many as before!
 
  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.
+
: I'm sure you can figure out what the above would do.
  
  
  
----
+
[[category:Leviticus]]
[[Prog Section 1]] | [[Prog Section 3]] | [http://www.ender.com/~jolinn/avendarbible/wiki.pl?Leviticus Leviticus -- Builder Resources Page]
+

Latest revision as of 20:42, 10 October 2014

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 non-local 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: the current line of set data prog  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.