Re: [CODE] Tried and failed this function...

From: JonB (Jon@theBarretts.com)
Date: 11/25/98


>Then I added ints like this. int dur = 0, eff = 0, targ = 0;
>
>dur += (strlen(arg2)-2);
>eff += (strlen(arg2)-1);
>targ += strlen(arg2);
>
>Then, I added some message, showing how much the dur, eff, and targ became
>when I casted the spell. I casted shield on myself with 000 (zero extra on
>duration, effect, and targets, thus making the spell "normal"), but it
>showed You shield yourself. Dur(1)  Eff(0)  Tar(3), which isn't right as
>it really should show You shield yourself. Dur(0)  Eff(0)  Tar(0).
>
>What could be wrong with the above strlen checks??

   I'm not sure what could be wrong with the strlen checks, as eff should
have been 2. But if you want to store the actual int value of each digit in
dur, eff, and targ, for example: 'shield self 321' would be dur=3, eff=2,
targ=1.  If that is the case, strlen is not what you want to use.  There
are a few ways you can get the value of each digit.  These will only work
assuming you can only use 0-9 for each power up, ie: you can do 2101,
dur=1, eff=10, targ=1.

The first one will use some charctrer arithmetic:
  dur = *arg2 - '0';
  eff = *(arg2+1) - '0';
  targ = *(arg2+2) - '0';
  In this example, the pointer notation will get each digit of arg2 and the
subtraction of '0' will basically convert the character to an integer.

Or you can use atoi and some equasions:
  number = atoi(arg2);
  dur = number/100;
  eff = (number/10)%10;
  targ = number%10;

That should do it for ya.  I like the first example the best, but they both
do the same thing, so use whichervr you prefer.  Hope that helps.

*<jB>*


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST