[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Saving spells with slots rather than sn's

Saving spells with slots rather than sn's

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1  2  3 

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #30 on Tue 03 Jul 2007 09:25 PM (UTC)

Amended on Tue 03 Jul 2007 10:25 PM (UTC) by Orik

Message
Ok, it successfully reads and writes the spells, now my problem lies in my do_memorize function. I mem heal, save and quit. Log back in and check pfile, heal is still in pfile as memorized. I use the command memorize and it shows that I have memmed no spells. I save and then check pfile again and it shows no memorized spells.

Here's part of my memorize function. I'm guessing I have to figure out how to call it to read words like in the save.c section:

do_memorize

    for (level = 9; level > 0; level--)
         {
              marker = FALSE;
              for (sn = 1; sn < MAX_SKILL; sn++)
                  {
                   if ( !skill_table[sn] || skill_table[sn]->spell_level != level )
                     continue;
                    total = 0;
                    for (i = 0; i < MAX_MEM_SPELLS; i++)
                       {
                          if ((ch->pcdata->memorized[ i] != 0)
                          && (ch->pcdata->memorized[ i] == sn))
                           {
                             total++;
                             none = 0;
                           }
                       }
                    if (total == 0)
                      continue;
                         if (marker)
                             {
                         if (total < 2)
                               sprintf(buf, "%s            %s\r\n", buf, skill_table[sn]->name);
                         else
                               sprintf(buf, "%s            %s (x%d)\r\n",buf, skill_table[sn]->name, total);
                             }
                    else
                    {
                       if (total < 2)
                       sprintf(buf, "%s (level %2d) %s\r\n", buf, skill_table[sn]->spell_level,
                       skill_table[sn]->name);
                       else
                       sprintf(buf, "%s (level %2d) %s (x%d)\r\n",buf, skill_table[sn]->spell_level,
                       skill_table[sn]->name, total);
                          marker = TRUE;
                     }
             }
       }

                if (none)
                        sprintf(buf, "%sNone.\r\n\r\n", buf);
                else

                                //sprintf(buf, "%s\r\n", buf);
                                strcat(buf, "\r\n");
                send_to_char(buf, ch);

                if (ch->pcdata->memorizing[0] != 0)
                                {
                mudstrlcpy(buf, "", MAX_STRING_LENGTH);
        strcat(buf, "And you are currently memorizing the following spells:\r\n");
                        time_memming = ch->mem_time;
                        for (i = 0; i < MAX_MEM_SPELLS; i++)
                                                {
                                if (ch->pcdata->memorizing[ i] != 0)
                                                                {
                                        sprintf(buf, "%s %4d seconds (%2d) %s.\r\n",
                                                buf,
                                                time_memming,
                                        skill_table[ch->pcdata->memorizing[ i]]->spell_level,
                                                                                skill_table[ch->pcdata->memorizing[ i]]->name);


I'm guessing it has to do with the for loops and memorized[ i] parts needing to be called by skill_table[sn]->name again.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #31 on Tue 03 Jul 2007 09:43 PM (UTC)
Message
Maybe I didn't quite fully fix the fread and fwrite.

I log in, mem heal
save
log out
log back in
check pfile, everything is in there
type mem, nothing in memorize function
save
check pfile, no memorized spells anymore
mem heal again
cast heal on self and it works just fine.

So there's still something wrong with it not reading the sn correctly to show the spell.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #32 on Tue 03 Jul 2007 10:14 PM (UTC)
Message
Woah, something really weird happened to your indenting there. :-P It's pretty hard to read when it goes all over the place like that...

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #33 on Tue 03 Jul 2007 10:19 PM (UTC)

Amended on Tue 03 Jul 2007 10:46 PM (UTC) by Orik

Message
Here's fwrite_char:


for (j = 0; j < MAX_MEM_SPELLS; j++)
 { 
   int sn = ch->memorized[j];
     if( skill_table[sn]->name != 0)
      fprintf(fp, "Memorized '%s'\n", skill_table[sn]->name ); 
}
 for (j = 0; j < MAX_MEM_SPELLS; j++)
  {
     int sn = ch->memorizing[j]; 
      if( skill_table[sn]->name != 0) 
     fprintf(fp, "Memorizing '%s'\n", skill_table[sn]->name );
 } 


Here's my fread code:


if( !strcmp( word, "Memorized" ) )
            {
               int sn;

                  sn = bsearch_skill_exact( fread_word( fp ), gsn_first_spell, gsn_first_skill - 1 );
                  if(sn < 0 )
                    bug ("%s", "Fread_char: unknown spell." );
                 fMatch = TRUE;
                  break;
            }
if( !strcmp( word, "Memorizing" ) )
            {
               int sn;

                  sn = bsearch_skill_exact( fread_word( fp ), gsn_first_spell, gsn_first_skill - 1 );
                  if(sn < 0 )
                    bug ("%s", "Fread_char: unknown spell." );
                 fMatch = TRUE;
                  break;
            }
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #34 on Tue 03 Jul 2007 10:26 PM (UTC)
Message
There, tried to make it better to read. Hope that helps.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #35 on Tue 03 Jul 2007 10:32 PM (UTC)
Message
Ah, much better, thank you.

You know, it occurs to me that you are writing our "Memorized:" with a colon, but I don't think the colons are skipped when you read in the data -- I could be wrong about that, I really don't remember. It might be worth trying to write without the colon and see what happens.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #36 on Tue 03 Jul 2007 10:36 PM (UTC)

Amended on Tue 03 Jul 2007 10:59 PM (UTC) by Orik

Message
actually, I do have them without the colons in my code. So that's not the problem.

********EXIT***********

Could the problem be that I'm not setting the sn to ch->pcdata->memorized[i] in the fread portion?
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #37 on Wed 04 Jul 2007 01:23 AM (UTC)
Message
Well, yes, you would have to update the memorized array with the skill you just read... :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #38 on Wed 04 Jul 2007 01:34 AM (UTC)

Amended on Wed 04 Jul 2007 01:36 AM (UTC) by Orik

Message
I came up with this:


if( !strcmp( word, "Memorized" ) )
            {
               int sn, j, i;
                 j = fread_number(fp);
                  sn = bsearch_skill_exact( fread_word( fp ), gsn_first_spell, gsn_first_skill - 1 );
                  if(sn < 0 )
                    bug ("%s", "Fread_char: unknown spell." );
                  ch->pcdata->memorized[ i] = sn;
                 fMatch = TRUE;
                  break;
            }
if( !strcmp( word, "Memorizing" ) )
            {
               int sn, j, i;
                 j = fread_number(fp);
                  sn = bsearch_skill_exact( fread_word( fp ), gsn_first_spell, gsn_first_skill - 1 );
                  if(sn < 0 )
                    bug ("%s", "Fread_char: unknown spell." );
                  ch->pcdata->memorizing[ i] = sn;
                 fMatch = TRUE;
                  break;
            }



Which it doesn't really work that well. It will remember the last spell I memorized. I mem spells, they all mem just fine, I save and log off, log back in and I have the last spell I memed in my memory.


How do I update the memorized array? What's the array? It is this right:

memorizing [ i ]
or
memorized [ i ]

How would I update it?
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #39 on Wed 04 Jul 2007 01:41 AM (UTC)
Message
There are a few problems here. You're using the variable i, but you never set it to anything, nor do you ever update it. You will want to initialize it to zero somewhere, and every time you make an assignment you want to update it.

But since you have memorized and memorizing, you actually need two variables. I suggest calling them something other than i, like numMemorized.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #40 on Wed 04 Jul 2007 02:59 AM (UTC)
Message
Ok, so I have it working...I believe.

What I did was, since I was counting the j in the fwrite I set it as the value in the fread. Then I changed the i to a j and since it was counting for every memed spell already, I just used that.

So far, I've been troubleshooting it, but it seems to be working. FINALLY!!! heh.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #41 on Wed 04 Jul 2007 03:33 AM (UTC)

Amended on Wed 04 Jul 2007 03:50 AM (UTC) by Orik

Message
Good news, it works. Bad news is somehow, I have no idea how, sset save skill table doesn't save through reboot or hotboot now. I tried it on my backup that i made before I switched spell memorization. It worked fine through reboot and hotboot.

I see that's it's saving in the class file, but when I hotboot/reboot, the level goes back up to 101 as if I never saved it. It shows minlevel in skills.dat as the level that I chose it, but it doesn't change in slookup.

i did a diff on tables.c, skills.c and save.c.

SKills.c had onthing, tables.c had nothing, save.c just had the changes to spell memorization.

bah, I thought I had it, now this is going to stump me.


*******EDIT*******

I just put those four changes into my backup folder and now everything works fine. For what I can tell anyways :)
[Go to top] top

Posted by Gadush   (92 posts)  [Biography] bio
Date Reply #42 on Thu 05 Jul 2007 06:16 PM (UTC)
Message
Been watching this with interest -- glad you have it figured out.
Any chance you might be willing to post your memorization system as a snippet? I've looked about for memorization for Smaug with no success.
Either way, glad you got it working.
Regards,
Gadush
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


85,795 views.

This is page 3, subject is 3 pages long:  [Previous page]  1  2  3 

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]