Prog Appendix 1

From Immwiki
Jump to: navigation, search

Appendix 1: Common Mob Prog Troubleshooting Issues

"I felt like destroying something beautiful"
-- Narrator, Fight Club

Over time, a great deal has been done to minimize the ways in which progs can crash the mud. However, people [Dovolente] often managed to find ways to do this. Consequently, this appendix has been created to help builders spot the most common types of crashes and problems we see.

Common Problem 1: Infinite Loops

The infinite loop is a classic cause of crashes, having its ancestry in the noble machinations of Captain Kirk, who used the loop to kill no less than three android villains, two evil AI’s, and the disembodied spirit of Jack the Ripper. Sadly, we live in an age that lacks such villains, so for us the infinite loop is to be eschewed.
Infinite loops can happen in a number of ways. The most common is when a program triggers itself. This situation is most often seen in a speech_prog, when a mobile speaks a word that is in itself the trigger for the prog.
Ex:
speech_prog p Jolinn
say Yes, Jolinn is quite the document scribe.
If you were to say "Jolinn" in this mob’s presence, it would say a phrase containing Jolinn. Then, this would trigger the mob’s prog again, and this would cause the mob to say a phrase containing Jolinn. This would also trigger the mob’s prog, and this process would continue indefinitely. Eventually, the mud’s process runs out of memory and space to handle such a large (infinite) number of loops, so it crashes. To avoid this sort of thing, make sure you contain no words that are in the triggering speech. Or, if the words are necessary, use npc checks.
Ex:
speech_prog p Jolinn
if ispc($n)
say Yes, Jolinn is quite the document scribe.
endif
This prog will only trigger if the speaker is a pc, and will therefore not cause an infinite loop.


Common Problem 2: Ghosts of Departed Entities

As we have seen, progs allow us to cause mobiles and objects to cease to exist, mainly through the use of the mppurge command. Unfortunately, careless progging can result in a situation where mobiles and objects purge themselves out of existence, then continue to execute prog commands. This will crash both the prog and the mud, as the mud will attempt to execute the prog, as if it were executed by a "NULL" object. This results in the mud trying to load/execute random memory elements, which results in the crash.
Ex:
prog add speech_prog p Begone!
mpecho With a rushing of wind, the air elemental disappears!
mppurge self
mpecho There is a soft "pop", as air rushes into to fill the void left by the elemental.
To fix this, always make sure that have no further commands after a self purge. If this is not possible (ex: a branch of an if check having an mppurge), use the break command to exit the prog.
Additional note - use of mpverbstop/opverbstop will kill the prog effectively, also avoiding the above problem. In fact, it is highly recommended to pair the use of any self-purgingness with a verbstop for safety.


Common Problem 3: Extra Spaces After Lines

Extra whitespace present at the end of a line can totally break the prog.
Ex:
mpvalueset 1 5
If there is an extra space after the '5' in the line above, the mob's v1 variable will not be set correctly to 5. In order to combat this, it might be useful to write progs offline in an editor that shows whitespace when you highlight text.

Common Problem 4: Dovolente