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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Adding a new obj string

Adding a new obj string

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


Pages: 1 2  

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Sat 25 Sep 2004 05:58 PM (UTC)

Amended on Sat 25 Sep 2004 06:16 PM (UTC) by Zeno

Message
I'm trying to add a new obj field, "creator". When I add it in the correct places, I get this on startup:

Sat Sep 25 19:54:16 2004 :: [*****] FILE: limbo.are LINE: 567
Sat Sep 25 19:54:16 2004 :: [*****] BUG: Fread_number: bad format. (%)



20 0 1
1 0 0 0
1 0 0
#3
coins gold~
%d gold coins~
A pile of gold coins.~


mud.h:
obj_index_data:

    char *              creator;   /* Custom items, who made it */

obj_data:

    char *              creator;   /* Custom items, who made it */


save.c:
fwrite_obj:
    if ( QUICKMATCH( obj->creator, obj->pIndexData->creator ) == 0 )
        fprintf( fp, "Creator      %s\n",       obj->creator         );

fread_obj:

            KEY( "Creator",     obj->creator,           fread_string( fp ) );


db.c:
load_objects:

        pObjIndex->creator              = fread_string( fp );

create_object:

    obj->creator        = QUICKLINK( pObjIndex->creator );

make_object:

          pObjIndex->creator            = STRALLOC( "" );


          pObjIndex->creator            = QUICKLINK( cObjIndex->creator );


I think thats about it. I've added a variable field before to objects, and it worked fine. Why is this not working?
It compiles without errors or warnings.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #1 on Sun 26 Sep 2004 06:22 AM (UTC)
Message
I beleive that the problem lies here:
 pObjIndex->creator              = fread_string( fp );
Area files are read in linearly to save space. So, if you have that line in when you haven't added the appropriate line into each and every object in all the area files. It may be trying to read in, say, a number, when its expecting a string.

There are two solutions that I can think of. 1) Utilize area version. This is my personal preference, as it allows alot of room for expansion, if you add something, just bump up the version and check for it. 2) Add in just writing a default string for writing. Log in, save all the areas, then add to read them in. Copyover/reboot, and your good, as the needed line is now in ever object in every file. This has its issues, though, specifically if you make a mistake with something, you need to make sure you backup your area files.

Hope that helps.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #2 on Sun 26 Sep 2004 04:32 PM (UTC)
Message
Area version? What do you mean/what is it?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #3 on Sun 26 Sep 2004 04:55 PM (UTC)

Amended on Sun 26 Sep 2004 04:59 PM (UTC) by Greven

Message
Well, the only part of area files that are not linear is reading in of the types, ie. rooms, objects, etc. In mud.h, find your area structure, and add
struct area_data
{
        int       version;
        AREA_DATA *next;
        AREA_DATA *prev;
If load_area, where the AREA_DATA is initialized, you should set version to a default of 0
        pArea->low_r_vnum = 0;
        pArea->low_o_vnum = 0;
        pArea->low_m_vnum = 0;
        pArea->hi_r_vnum = 0;
        pArea->hi_o_vnum = 0;
        pArea->hi_m_vnum = 0;
        pArea->version = 0;
Look in load_area_file in db.c, and you can add something like this:
                else if (!str_cmp(word, "AUTHOR"))
                        load_author(tarea, fpArea);
                else if (!str_cmp(word, "VERSION"))
                        tarea->version = fread_number(fpArea);
                else if (!str_cmp(word, "FLAGS"))
Then, in fold_area you could throw in
        fprintf(fpout, "#AREA   %s~\n\n\n\n", tarea->name);
        fprintf(fpout, "#VERSION %d\n\n", AREA_VERSION);
        fprintf(fpout, "#AUTHOR %s~\n\n", tarea->author);
Since the reading in is an if check, it won't crash if VERSION is not there, as opposed to load_objects, where it will.

What I did was did a global declaration for AREA_VERSION in mud.h, and just increment it when you make a code change.

So now, you could go to load_objects, and add something like this
                pObjIndex->name = fread_string(fp);
                pObjIndex->short_descr = fread_string(fp);
                pObjIndex->description = fread_string(fp);
                pObjIndex->action_desc = fread_string(fp);
                if ( tarea->version > 0 )
                pObjIndex->creator = fread_string( fp );

                pObjIndex->description[0] = UPPER(pObjIndex->description[0]);


This format give you alot of growth room for the future, as now if you need to modify your area files, it will be alot easier. You can even use this to as a marker. I made a function to read in stock SWR areas and convert them to my format, and I was able to find out very easily what I had changed and how I had to modify the stock one.

That should be all you need, hope that helps.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #4 on Sun 26 Sep 2004 08:24 PM (UTC)
Message
I started doing that, and ran into this in fold_area:



    fprintf( fpout, "#VERSION %d\n", AREA_VERSION_WRITE );


Erm. I didn't see a version field in the area structure either.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #5 on Sun 26 Sep 2004 09:48 PM (UTC)

Amended on Sun 26 Sep 2004 09:49 PM (UTC) by Greven

Message
So... It didn't work? If you've got an area version already being written/read, then all you have to do increase it and add the check. What they may have done is set a global variable to whatever is read in, and it may check that. If somethings not working, just let us know and we can give you a solution.

Keep in mind though that my solution may differ from what the original smaug was using, as I'm using SWR, and as far as I know that was not part of stock SWR

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #6 on Sun 26 Sep 2004 11:43 PM (UTC)
Message
It worked, I'm just not sure how its going to work. If I have version in, what now? Do I have to manually edit each object in every area?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #7 on Mon 27 Sep 2004 12:58 AM (UTC)
Message
No, the version is not for a specific object, but for the entire area file. Before you read everything in(without the creator string) its version 0. Everything loads, and a default is put in for creator, probably the area author for now I would assume. Then, when this area is saved, it will write version 1 to the file, as well as the creator string. Next time that area is read in, it will detect that its version 1, and now it will assume that a creator string is there, and read it in, which is ok now, cause it is.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #8 on Mon 27 Sep 2004 01:15 AM (UTC)
Message
I meant edit each object to add the creator field, not the version.

What function would I have the creator field default stored?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #9 on Mon 27 Sep 2004 01:54 AM (UTC)
Message
Probably what to do it where the object index is initialized, but it looks like you got that covered in make_object.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #10 on Mon 27 Sep 2004 09:48 PM (UTC)
Message
I understand most of what you're saying, except I'm not quite sure what I have to add now. Its one of those "Ohhhhh, now I get it" things, eh. Just add the ifcheck, then have it set the creator to a string?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #11 on Mon 27 Sep 2004 10:31 PM (UTC)
Message
You do have it set where, in make_object, you are initializing the string, either copying it from the pre-existing object or setting it to blank( you may want to make the copied one, the new one, default to the creators name). What I don't see in your first post is somwhere in fold_area to write the strings for the object indexes to the area files. If your planning on reading it in from right below the actiondesc, then you want to add a line like this:
                fprintf(fpout, "%s~\n", pObjIndex->name);
                fprintf(fpout, "%s~\n", pObjIndex->short_descr);
                fprintf(fpout, "%s~\n", pObjIndex->description);
                fprintf(fpout, "%s~\n", pObjIndex->action_desc);
                fprintf(fpout, "%s~\n", pObjIndex->creator);


Then in load_objects, you could use something like such
                pObjIndex->name = fread_string(fp);
                pObjIndex->short_descr = fread_string(fp);
                pObjIndex->description = fread_string(fp);
                pObjIndex->action_desc = fread_string(fp);
                if ( tarea->version > 0 )
                    pObjIndex->creator = fread_string( fp );
                else
                    pObjIndex->creator = STRALLOC(tarea->author);
This says basically that if it is greater than version 0(so one with the creator string written to the files), read in that string, otherwise we know that that string is not there, but since we have nothing to set to it, lets default the objects creator field to the name of the areas author. Then from there it can be copied when you create a new object index, or when you create an instance of that object.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #12 on Tue 28 Sep 2004 01:45 AM (UTC)
Message
What about area version? Where would I have that changed?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #13 on Tue 28 Sep 2004 04:20 AM (UTC)
Message
you should change the area version from whereever its declared, likely in mud.h, you can grep it to be should

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #14 on Sat 09 Oct 2004 04:03 PM (UTC)
Message
Finally got around to doing this. Ran into a problem. Players eq crashes the MUD.
#OBJECT
Creator      (null)
Vnum         2672
Level        108
Values       12 100 20000 3 0 0
End


#0  0x080fd652 in fread_obj (ch=0x820ffe0, fp=0x83a87f0, os_type=0) at save.c:2046
2046                            obj->name = QUICKLINK( obj->pIndexData->name );
(gdb) bt
#0  0x080fd652 in fread_obj (ch=0x820ffe0, fp=0x83a87f0, os_type=0) at save.c:2046
#1  0x0809feed in nanny (d=0x83a4908, argument=0x83a87f0 "\230$­û") at comm.c:2409
#2  0x0809d015 in game_loop () at comm.c:668
#3  0x0809c963 in main (argc=2, argv=0xbfffdc70) at comm.c:304
#4  0x42015967 in __libc_start_main () from /lib/i686/libc.so.6


obj->name is null.
How can this be fixed?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[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.


39,914 views.

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

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]