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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  New item types

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: New item types
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1  2 3  

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Wed 22 Aug 2007 01:22 PM (UTC)  quote  ]
Message
I believe that was the problem. One whole space caused me quite a bit of grief...heh. It loads the object with the socket values now.

Only thing now is that when I save my char, quit, and log back in, the used sockets don't load on the object, but I believe I know how to fix that so I'll just have to wait and do that once I get home from work tonight.

Thanks for the help guys.
[Go to top] top

Posted by Gohan_TheDragonball   USA  (183 posts)  [Biography] bio
Date Wed 22 Aug 2007 08:04 AM (UTC)  quote  ]

Amended on Wed 22 Aug 2007 08:07 AM (UTC) by Gohan_TheDragonball

Message
only my suggestion but here is how i would have done this:

            if( !str_cmp( word, "Socket" ) )
            {
               int x = fread_number(fp);
               pObjIndex->socket[x] = fread_number(fp);
               pObjIndex->usocket[x] = fread_number(fp);
               break;
            }

    for ( sock = 0; sock < 6; sock++ )
        fprintf( fpout, "Socket   %d %d %d\n", sock, pObjIndex->socket[sock], pObjIndex->usocket[sock]);


cuts you down from around 40 lines to 8 and reduces you from 26 variables to 2.
[Go to top] top

Posted by Gohan_TheDragonball   USA  (183 posts)  [Biography] bio
Date Wed 22 Aug 2007 04:08 AM (UTC)  quote  ]
Message
you might wanna do something like this:

            if( !str_cmp( word, "#ENDOBJECT" ) )
            {
               if( !pObjIndex->description )
                  pObjIndex->description = STRALLOC( "" );
               if( !pObjIndex->action_desc )
                  pObjIndex->action_desc = STRALLOC( "" );
               if( !pObjIndex->sdesc1 )
                  pObjIndex->sdesc1 = STRALLOC( "" );
               if( !pObjIndex->sdesc2 )
                  pObjIndex->sdesc2 = STRALLOC( "" );
               if( !pObjIndex->sdesc3 )
                  pObjIndex->sdesc3 = STRALLOC( "" );
               if( !pObjIndex->sdesc4 )
                  pObjIndex->sdesc4 = STRALLOC( "" );
               if( !pObjIndex->sdesc5 )
                  pObjIndex->sdesc5 = STRALLOC( "" );
               if( !pObjIndex->sdesc6 )
                  pObjIndex->sdesc6 = STRALLOC( "" );
            ....

and my guess is that your use of "Used Sockets" in the write and read procedure is whats messing you up. you are supposed to use a single word, in your case sscanf is messing up since your reading "Sockets 0 0 0 0 0 0". dump the space and make it "UsedSockets" and see if the problem persists. you would have noticed this problem from the beginning except since you are scanning the whole line, the surplus at the end of the line is discarded and the error warning does not come up since there is no extra words in the file. just for the record, in this case you should not be using sscanf, but instead just using fread_number() each time. i am actually surprised its even still being used, i figured when samson switched to this area format he would get rid of it and save/read every variable separately.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Wed 22 Aug 2007 12:55 AM (UTC)  quote  ]
Message
The object itself writes correctly to the area file. And it loads correctly on startup. When I oinvoke the socket numbers are all 0, but when I check the area file they are the numbers that they need to be. So it needs to be in create_object I would think.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Wed 22 Aug 2007 12:53 AM (UTC)  quote  ]
Message
Create_object

   obj->wear_flags = pObjIndex->wear_flags;
   obj->value[0] = pObjIndex->value[0];^M
   obj->value[1] = pObjIndex->value[1];^M
   obj->value[2] = pObjIndex->value[2];^M
   obj->value[3] = pObjIndex->value[3];^M
   obj->value[4] = pObjIndex->value[4];^M
   obj->value[5] = pObjIndex->value[5];^M
^M
   obj->socket[0] = pObjIndex->socket[0];^M
   obj->socket[1] = pObjIndex->socket[1];^M
   obj->socket[2] = pObjIndex->socket[2];^M
^M
   obj->usocket[0] = 0;^M
   obj->usocket[1] = 0;^M
   obj->usocket[2] = 0;^M
^M
   obj->weight = pObjIndex->weight;
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Wed 22 Aug 2007 12:48 AM (UTC)  quote  ]
Message
fwrite_fuss_project

   val0 = pObjIndex->value[0];^M
   val1 = pObjIndex->value[1];^M
   val2 = pObjIndex->value[2];^M
   val3 = pObjIndex->value[3];^M
   val4 = pObjIndex->value[4];^M
   val5 = pObjIndex->value[5];^M
^M
   sock0 = pObjIndex->socket[0];^M
   sock1 = pObjIndex->socket[1];^M
   sock2 = pObjIndex->socket[2];^M
   sock3 = pObjIndex->socket[3];^M
   sock4 = pObjIndex->socket[4];^M
   sock5 = pObjIndex->socket[5];^M
^M
   usock0 = pObjIndex->usocket[0];^M
   usock1 = pObjIndex->usocket[1];^M
   usock2 = pObjIndex->usocket[2];^M
   usock3 = pObjIndex->usocket[3];^M
   usock4 = pObjIndex->usocket[4];^M
   usock5 = pObjIndex->usocket[5];^M

further down:

   fprintf( fpout, "Values   %d %d %d %d %d %d\n", val0, val1, val2, val3, val4, val5 );^M
   fprintf( fpout, "Socketable       %d\n", pObjIndex->socket_item );^M
   fprintf( fpout, "Sockets   %d %d %d %d %d %d\n", sock0, sock1, sock2, sock3, sock4, sock5 );^M
   fprintf( fpout, "Used Sockets   %d %d %d %d %d %d\n", usock0, usock1, usock2, usock3, usock4, usock5 );^M
   fprintf( fpout, "Stats    %d %d %d %d %d\n", pObjIndex->weight,
            pObjIndex->cost, pObjIndex->rent ? pObjIndex->rent : ( int )( pObjIndex->cost / 10 ),
            pObjIndex->level, pObjIndex->layers );
^M
   if( pObjIndex->sdesc1 && pObjIndex->sdesc1[0] != '\0' )^M
      fprintf( fpout, "Socket1     %s~\n", pObjIndex->sdesc1 );^M
   if( pObjIndex->sdesc2 && pObjIndex->sdesc2[0] != '\0' )^M
      fprintf( fpout, "Socket2     %s~\n", pObjIndex->sdesc2 );^M
   if( pObjIndex->sdesc3 && pObjIndex->sdesc3[0] != '\0' )^M
      fprintf( fpout, "Socket3     %s~\n", pObjIndex->sdesc3 );^M
   if( pObjIndex->sdesc4 && pObjIndex->sdesc4[0] != '\0' )^M
      fprintf( fpout, "Socket4     %s~\n", pObjIndex->sdesc4 );^M
   if( pObjIndex->sdesc5 && pObjIndex->sdesc5[0] != '\0' )^M
      fprintf( fpout, "Socket5     %s~\n", pObjIndex->sdesc5 );^M
   if( pObjIndex->sdesc6 && pObjIndex->sdesc6[0] != '\0' )^M
      fprintf( fpout, "Socket6     %s~\n", pObjIndex->sdesc6 );^M
^M
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Wed 22 Aug 2007 12:22 AM (UTC)  quote  ]
Message
maximum is 6000 chars. I'll post my code.
fread_fuss_object
Here's my sockets.

            if( !str_cmp( word, "Sockets" ) )^M
            {^M
               char *ln = fread_line( fp );^M
               int x1, x2, x3, x4, x5, x6;^M
               x1 = x2 = x3 = x4 = x5 = x6 = 0;^M
^M
               sscanf( ln, "%d %d %d %d %d %d", &x1, &x2, &x3, &x4, &x5, &x6 );^M
^M
               pObjIndex->socket[0] = x1;^M
               pObjIndex->socket[1] = x2;^M
               pObjIndex->socket[2] = x3;^M
               pObjIndex->socket[3] = x4;^M
               pObjIndex->socket[4] = x5;^M
               pObjIndex->socket[5] = x6;^M
^M
               break;^M
            }^M
            KEY( "Socketable", pObjIndex->socket_item, fread_number( fp ) );^M
            KEY( "Socket1", pObjIndex->sdesc1, fread_string( fp ) );^M
            KEY( "Socket2", pObjIndex->sdesc2, fread_string( fp ) );^M
            KEY( "Socket3", pObjIndex->sdesc3, fread_string( fp ) );^M
            KEY( "Socket4", pObjIndex->sdesc4, fread_string( fp ) );^M
            KEY( "Socket5", pObjIndex->sdesc5, fread_string( fp ) );^M
            KEY( "Socket6", pObjIndex->sdesc6, fread_string( fp ) );^M

Here's Values

         case 'V':
            if( !str_cmp( word, "Values" ) )
            {
               char *ln = fread_line( fp );
               int x1, x2, x3, x4, x5, x6;
               x1 = x2 = x3 = x4 = x5 = x6 = 0;

               sscanf( ln, "%d %d %d %d %d %d", &x1, &x2, &x3, &x4, &x5, &x6 );

               pObjIndex->value[0] = x1;
               pObjIndex->value[1] = x2;
               pObjIndex->value[2] = x3;
               pObjIndex->value[3] = x4;
               pObjIndex->value[4] = x5;
               pObjIndex->value[5] = x6;

               break;
            }

Here's used sockets


                 case 'U':^M
                        if( !str_cmp( word, "Used Sockets" ) )^M
            {^M
               char *ln = fread_line( fp );^M
               int x1, x2, x3, x4, x5, x6;^M
               x1 = x2 = x3 = x4 = x5 = x6 = 0;^M
^M
               sscanf( ln, "%d %d %d %d %d %d", &x1, &x2, &x3, &x4, &x5, &x6 );^M
^M
               pObjIndex->usocket[0] = x1;^M
               pObjIndex->usocket[1] = x2;^M
               pObjIndex->usocket[2] = x3;^M
               pObjIndex->usocket[3] = x4;^M
               pObjIndex->usocket[4] = x5;^M
               pObjIndex->usocket[5] = x6;^M
^M
               break;^M
            }^M
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Tue 21 Aug 2007 07:20 PM (UTC)  quote  ]
Message
I am using Smaugfuss1.8.

I'll get more detailed information when I get home from work. I'll check out sscanf as well.

[Go to top] top

Posted by Isthiriel   (111 posts)  [Biography] bio
Date Tue 21 Aug 2007 08:05 AM (UTC)  quote  ]
Message
Hmm. Not really enough information to work from.

I assume you're running some version of SmaugFuss?

Have you tried examining sscanf's return value?

I might be able to help more with the complete listings of fread_fuss_object, fwrite_fuss_object and create_object :-/ (Is there any way to attach files to posts here?)
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Tue 21 Aug 2007 12:20 AM (UTC)  quote  ]
Message
So when I set

obj->socket[0] = 1;
obj->socket[1] = 2;
obj->socket[2] = 3;

It was able to load as 1, 2, and 3. When I set it back to

  obj->socket[0] = pObjIndex->socket[0];
   obj->socket[1] = pObjIndex->socket[1];
   obj->socket[2] = pObjIndex->socket[2];


It showed 0 again on oinvoking. The area file still read that it was what it was supposed to be, it just loaded as 0's.

I then added 3 more value types in all the respective areas and added the 3 new value types in create_object and when I loaded, set the new value types, savea, checked file, was still correct, shutdown, checked file again, was correct, booted up, correct, oinvoke, the three new value types were 0 on the object even though they were correct in the area file.

Gah, this is annoying.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Sun 19 Aug 2007 07:36 PM (UTC)  quote  ]

Amended on Sun 19 Aug 2007 08:04 PM (UTC) by Orik

Message
On to round 5 of this madness.

Everything is working except for the loading of the item.

It writes successfully in fwrite_fuss_object, but in fread_fuss_object it doesn't read it correctly. It just sets the Socket values back to 0. I copied the Item values code pretty much so here's what Sockets looks like in fread_fuss_object:


           if( !str_cmp( word, "Sockets" ) )
            {
               char *ln = fread_line( fp );
               int x1, x2, x3, x4, x5, x6;
               x1 = x2 = x3 = x4 = x5 = x6 = 0;

               sscanf( ln, "%d %d %d %d %d %d", &x1, &x2, &x3, &x4, &x5, &x6 );

               pObjIndex->socket[0] = x1;
               pObjIndex->socket[1] = x2;
               pObjIndex->socket[2] = x3;
               pObjIndex->socket[3] = x4;
               pObjIndex->socket[4] = x5;
               pObjIndex->socket[5] = x6;

               break;
            }


It's setting the values back at 0. When I savearea and check the file to see if it saved, it'll say

"Sockets 1 1 2 0 0 0"

That means that i had 1 blue, 1 red, 2 yellow sockets. It shows it directly in the area file after a savearea. Then when I reboot or shutdown and start again, the file loads as

"Sockets 0 0 0 0 0 0"

So for some odd reason, the socket value isn't carrying over.

**EDIT**
Ok, I've found out that it loads with the socket values, but when I oinvoke and ostat the sword it shows no values. Then when I savearea it saves to "Sockets 0 0 0 0 0 0"

do_ostat

   ch_printf_color( ch, "&cSocketed Slots : &BBlue &z(&w%d/&W%d&z) &RRed &z(&w%d/&W%d&z) &YYellow &z&z(&w%d/&W%d&z)&w\r\n",
                    obj->pIndexData->usocket[0], obj->pIndexData->socket[0], 
                                        obj->pIndexData->usocket[1], obj->pIndexData->socket[1],
                    obj->pIndexData->usocket[2], obj->pIndexData->socket[2]);


it shows "Socketed Slots : Blue (0/0) Red (0/0) Yellow (0/0)"

when it should show
"Socketed Slots : Blue (0/1) Red (0/1) Yellow (0/2)"

I'm guessing it's going to be in db.c create_object function. hmm..

create_object

   obj->socket[0] = pObjIndex->socket[0];
   obj->socket[1] = pObjIndex->socket[1];
   obj->socket[2] = pObjIndex->socket[2];

   obj->usocket[0] = 0;
   obj->usocket[1] = 0;
   obj->usocket[2] = 0;
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sun 19 Aug 2007 10:48 AM (UTC)  quote  ]
Message
Quote:
And if that's SMAUG's standard idiom for it, then it badly needs at least some utility functions to clean it up and/or conversion to a linked-list structure.

Groan. Don't get me started on places where SMAUG could use utility functions to make things cleaner, safer and easier to understand. #1 and #3 are just cosmetic (still important in my book) but I think everybody would agree that #2 is good no matter what...

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Isthiriel   (111 posts)  [Biography] bio
Date Sun 19 Aug 2007 08:36 AM (UTC)  quote  ]
Message
So STRFREE is null-checked?

Quote:
However the problem I see now is that if there is an existing description, however you want the new one to be different, then it won't be.


That's why it's repeated six times with else-ifs. It tries to put buf1 in each of the six sdesc slots, until it either succeeds (by finding an "empty" slot) or runs off the end.

And if that's SMAUG's standard idiom for it, then it badly needs at least some utility functions to clean it up and/or conversion to a linked-list structure.

... just because it's C doesn't mean you can't make it object-oriented :)
[Go to top] top

Posted by Nick Gammon   Australia  (18,801 posts)  [Biography] bio   Forum Administrator
Date Sun 19 Aug 2007 06:12 AM (UTC)  quote  ]
Message
Er, no I don't think so. The way it was written it did this:


  • If there is no description pointer, or
  • If there is a description pointer, and it was an empty string


Then:


  • Free the old description pointer (which would have no effect if the pointer was NULL) - however if it was the empty string it would be freed.


However the problem I see now is that if there is an existing description, however you want the new one to be different, then it won't be.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Isthiriel   (111 posts)  [Biography] bio
Date Sun 19 Aug 2007 05:46 AM (UTC)  quote  ]
Message
Strictly, shouldn't it be:
if (second_ob->sdesc1 && second_ob->sdesc1[0] == '\0') {
  STRFREE(second_ob->sdesc1);
}
if (!second_ob->sdesc1) { /* or == NULL for Correctness */
  second_ob->sdesc1 = STRALLOC(buf1);
}

Because otherwise you're leaking a byte everytime the function runs.
[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.


7,735 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]