home » builders » builder's lessons » string if check function

String if check function

The string and stringprefix functions are very powerful code added to the game in 2004 by Tyr. It gives builders alot of power and flexibility in their programs allowing them to check for all sorts of conditions.

And example of how it has been used so far in the game, has been to work out what spell has been cast, so that an intercept program on cast reacts a certain way to different spells.

>intercept_prog cast~
if quest(5,5,$n) == 6
  if stringprefix($1) == friends
    mpunintercept
    if string($2) == leperous
    or string($2) == witch
      mpunintercept
      mpmset self flags sentinel
      mpecho $I gasps and looks cautiously at her reflection in the floors.
      mpecho $I doesn't look that much better to you, but seems overjoyed as she scuttles to your side.
      sayto $n Oh, thank you! For your help, 
      sayto $n I will tell you that my husband
      sayto $n is an expert on the knowledge you
      sayto $n seek, but in his current state he
      sayto $n is too sleep deprived to be of any
      sayto $n help to you.
      sayto $n I have a thought on the matter.
      sayto $n Are you willing to listen?
      mpmset $n quest 5 5 7
    else
      mpunintercept
    endif
  else
    mpunintercept
  endif
else
  mpunintercept
endif
~

In this prog we wanted to determine if the PC was casting friends. If so they would be doing what the quest wanted of them. $0 is the entire line after the command. $1 is the first argument/word, $2 is the second and so on, up to $9. The word cast is not processed by the string functions, it is processed by the actual intercept, so it is not part of the equation.

You could also do cast 'word of recall'. This would make $0 would be "word of recall", $1 would be "word of recall", $2 would be undefined. Anything inside quotes counts as a single argument where these $# variables are concerned just as in a command like cast.

The difference between string and stringprefix, is that string will require the whole word to be typed in that is being checked for, stringprefix will be satisfied for just a few letters being typed in. This helps builders deal with lazy typists :)