home » builders » builder's lessons » program layout

Program layout

Spacing of programs

It is important to use spacing in your programs. It helps to see, and find errors in programs. For every if check you should indent your program by 2 spaces. This way you can see that every if check has its own endif.

The area admins will insist on correctly spaced programs. It makes it far easier for us to be able to read the programs, and as my old programming teacher drummed into me, neatly laid out code is very important.

>time_prog 6~
if rand(20)
  mpgoto 8030
  mpecho The Town Crier starts his rounds.
else
  if rand(20)
    mpgoto 8511
    mpecho The Town Crier starts his rounds.
  else
    if rand(20)
      mpgoto 8385
      mpecho The Town Crier starts his rounds.
    else
      if rand(20)
        mpgoto 8810
        mpecho The Town Crier starts his rounds.
      else
        mpgoto 8631
        mpecho The Town Crier starts his rounds.
      endif
    endif
  endif
endif
~
|

The above prog is the program from the Waterdeep Town Crier. For every if check the following parts of the program is indented two spaces. It is very easy to match up the following endifs. The more complex a program gets the more important this spacing becomes to you. It really does make a difference, Dalvyn has created some super long programs that actually used up the coded limit for programs. He had to remove his spaces, to make them fit. He had a missing endif in there one time, and it was near impossible to find because the program was not spaced.

Tildas and pipes

Often new builders are not sure where tildas (~) and pipes (|) go. At the end of each prog line, the first line of the prog is a tilda, and at the end of the program. The pipe only goes AFTER all the progs for that particular mobile/object/room. Each program that the mobile has is ended by a tilda.

Here is a sample of multiple progs on a mobile.

#8050
Piergieron~
Piergieron~
Lord Piergieron stands here.
~
He is the acknowledged ruler of Waterdeep, but in reality he is just one
of the council of twelve Lords of Waterdeep.  Most of the lords are secret,
but it is generally know that Piergieron is one of the council.
~
U 50 CLASS_FIGHTERS RACE_HUMAN SEX_MALE POS_STANDING DEITY_NONE
ACT_REQUEST|ACT_SENTINEL|ACT_NOSHOVE|ACT_CITIZEN
0
ARMOR_TYPE_BANDED MATERIAL_BRASS
d15+15 1000
13 13 13 18 13 18 13
0 0 0 0 0
LANG_COMMON
LANG_COMMON
RIS_NONE RIS_NONE RIS_NONE
%15 2 charisma~
> death_prog 100~
if questr(15100, 19, 5, $n) == 12
  mpoload 8073
  mpechoat $n You have killed the most well known Lord of Waterdeep!
  mpechoaround $n $n has killed the most well known Lord of Waterdeep!
  mpmset $n questr 15100 19 5 13
endif
~
>intercept_prog sleep~
sayto $n You cannot sleep here.
sayto $n Go pay for a room in an inn.
~
>give_prog i7007~
sayto $n Argh! What are you giving me this disgusting thing for?
drop i7007
mpecho Lord Piergieron grimaces in disgust.
sayto $n My officials handles the rewards for this head.
sayto $n During the day they can be found any of the gates.
~
|

Lord Piergieron has 3 programs on him for the purpose of this example, in the game he actually has much more. Each is finished by a tilda, but at the end of the last one before the next mobiles information starts is the pipe.