Top Mud Sites Forum Return to TopMudSites.com
Go Back   Top Mud Sites Forum > Mud Development and Administration > MUD Coding
Click here to Register

Reply
 
Thread Tools
Old 01-12-2003, 10:40 PM   #1
visko
Member
 
Join Date: May 2002
Posts: 98
visko is on a distinguished road
Send a message via ICQ to visko Send a message via AIM to visko
I'm restructuring OLC a bit, and in the process I've created a new editor type, which I'm putting into a new .are file. The problem is, I'm getting very odd error messages from bug, to the tune of "Can't find the corrent information from line 0 of your file." This is true because there IS no line 0 of that file. Any reason this code would be looking for line 0 instead of line 1 to start out with? Are there any other things wrong with the code that I can't see because I'm blind?
--------------------------------------------
void load_segments( FILE *fp )
{
SEG_DATA *pSeg;
char *word, line[128];
int i, j;
fgets(line, sizeof(line), fp);
word = fread_word(fp);
if (!str_cmp(word, "Segments"))
i = fread_number(fp);
else
bug("ERROR: Number of Segments not defined.", 0);
for (j = 0; j < i; j++)
{
pSeg = alloc_perm(sizeof(pSeg));
pSeg->vnum = j;
pSeg->name = fread_string(fp);
pSeg->builders = fread_string(fp);
pSeg->seg_flags = fread_number(fp);
pSeg->credit = fread_string(fp);
}
fclose(fp);
}
-----------
I should be adding to this function, especially since this'll end up a linked list, but for now since I only have one segment, wth?
-Visko
visko is offline   Reply With Quote
Old 01-13-2003, 10:38 AM   #2
jornel
Member
 
Join Date: Sep 2002
Location: Canada
Posts: 73
jornel is on a distinguished road
I suspect it has something to do with intermixing standard C library file functions fgets - which doesn't increment the mud's line number variable - with mud file library routines fread_xxx which do.


Questions to ask yourself:
- is the .are file actually opened? by routines which initialize the line number?
- why are you fgetsing into a buffer called line, then never using it?

To help you figure out which fread_xxx() call is causing the bug message, insert your own test bug messages before and after the calls to fread_number() so that you can recognize where the program is.

bug("Test: Before the fgets");
bug("Test: Between fgets and fread"):
etc.

After the problem is diagnosed and solved, you remove the test bugs.

Hope this helps.
jornel is offline   Reply With Quote
Old 01-13-2003, 07:10 PM   #3
visko
Member
 
Join Date: May 2002
Posts: 98
visko is on a distinguished road
Send a message via ICQ to visko Send a message via AIM to visko
visko is offline   Reply With Quote
Old 01-13-2003, 07:18 PM   #4
visko
Member
 
Join Date: May 2002
Posts: 98
visko is on a distinguished road
Send a message via ICQ to visko Send a message via AIM to visko
visko is offline   Reply With Quote
Old 01-13-2003, 11:16 PM   #5
jornel
Member
 
Join Date: Sep 2002
Location: Canada
Posts: 73
jornel is on a distinguished road
jornel is offline   Reply With Quote
Old 01-14-2003, 03:07 AM   #6
visko
Member
 
Join Date: May 2002
Posts: 98
visko is on a distinguished road
Send a message via ICQ to visko Send a message via AIM to visko
visko is offline   Reply With Quote
Old 01-14-2003, 10:12 AM   #7
jornel
Member
 
Join Date: Sep 2002
Location: Canada
Posts: 73
jornel is on a distinguished road
Glad I could help.

Here's a tip to avoid future woes: have your file opens and file closes in the same higher-level routine, with calls to the section reading routines in the middle. Its cleaner, and you avoid unnecessary (and sometime unexpected) side-effects.
jornel is offline   Reply With Quote
Old 01-16-2003, 02:17 AM   #8
visko
Member
 
Join Date: May 2002
Posts: 98
visko is on a distinguished road
Send a message via ICQ to visko Send a message via AIM to visko
Ok, well it reads. But my problems haven't ended. I tried editing the segment I loaded, and it didn't work. On a whim, I threw in a function that listed the current loaded segments. This is what I got:

<1500/1500hp 900/900mv> slist
[Num] [Seg Name ] (Builders) [Credit ]
[1076573508] (null) (null)
[1076573532] (null) @6+@

(Please ignore the bad spacings; I'm cleaing that up later, this was just a hack from alist.)

As you can see, the numbers are a tad wrong (they should start at 1 and move upwards from there...), and the names/builders/credits are just...off. And I don't know why. Does this kind of screwup look familiar to anyone?

Thanks so much, I'll post any other code people want to see to get to the bottom of this.

-Visko
visko is offline   Reply With Quote
Old 01-16-2003, 08:23 AM   #9
jornel
Member
 
Join Date: Sep 2002
Location: Canada
Posts: 73
jornel is on a distinguished road
It doesn't look like you are printing your data, you have a bad or missing pointer to your information.  To know more, I'd need to see the line(s) before and upto the line that printed that display.

I also noticed that in your original function you allocate a structure, keep a pointer to it in the variable pSeg, read your strings from the file and then exit.  But no other function can reference this data, since the variable pSeg disappears when load_segments() returns.
jornel is offline   Reply With Quote
Old 01-16-2003, 09:40 PM   #10
visko
Member
 
Join Date: May 2002
Posts: 98
visko is on a distinguished road
Send a message via ICQ to visko Send a message via AIM to visko
Right, sorry, I was getting ahead of myself. Let me repost some of the functions, they've changed a bit. There's a few other things to show, as well, I suppose...

void load_segments( FILE *fp )
{
SEG_DATA *pSeg;
char *word, line[128];
int i, j;
fgets(line, sizeof(line), fp);
word = fread_word(fp);
if (!str_cmp(word, "Segments"))
i = fread_number(fp);
else
bug("ERROR: Number of Segments not defined.", 0);
for (j = 1; j <= i; j++)
{
pSeg = alloc_perm(sizeof(pSeg));
pSeg->vnum = j;
pSeg->name = fread_string(fp);
pSeg->builders = fread_string(fp);
pSeg->seg_flags = fread_number(fp);
pSeg->credit = fread_string(fp);
if ( seg_first == NULL )
seg_first = pSeg;
if ( seg_last != NULL )
seg_last->next = pSeg;
seg_last = pSeg;
pSeg->next = NULL;
top_seg++;
}
}

That's the loading function; seg_first and seg_last are globally defined.

The listing function is the following:
void do_slist( CHAR_DATA *ch, char *argument )
{
char buf [ MAX_STRING_LENGTH ];
char result [ MAX_STRING_LENGTH*2 ]; /* May need tweaking. */
SEG_DATA *pSeg;

sprintf( result, "[%3s] [%-27s] (%-8s) [%-10s]\n\r",
"Num", "Seg Name", "Builders", "Credit" );

for ( pSeg = seg_first; pSeg; pSeg = pSeg->next )
{
sprintf( buf, "[%3d] %-29s %-5s %-12s\n\r",
pSeg->vnum,
pSeg->name,
pSeg->builders,
pSeg->credit);
strcat( result, buf );
}
send_to_char( result, ch );
return;
}

Segment structure is the following:

/*
* Segment definition. Work in progress. --Visko
*/
struct segment_data
{
SEG_DATA * next;
char * name;
char * builders;
int seg_flags;
char * credit;
int vnum;
};

Lesse, anything else....

I think that's about it for loading and displaying. If there's anything else you need, or anything obviously wrong, just post and I'll do what I can.

Thanks,
-Visko
visko is offline   Reply With Quote
Old 01-16-2003, 10:34 PM   #11
jornel
Member
 
Join Date: Sep 2002
Location: Canada
Posts: 73
jornel is on a distinguished road
jornel is offline   Reply With Quote
Old 01-17-2003, 12:46 AM   #12
visko
Member
 
Join Date: May 2002
Posts: 98
visko is on a distinguished road
Send a message via ICQ to visko Send a message via AIM to visko
visko is offline   Reply With Quote
Reply


Thread Tools


File I/O problems - Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems compiling SMAUG dalalphabet MUD Administration 2 02-17-2004 09:34 PM
problems with smaug 1.4 objects Shao_Long MUD Builders and Areas 5 07-05-2002 01:16 PM
Connect/Disconnect Problems Skorpian MUD Coding 2 06-28-2002 10:43 PM

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -4. The time now is 04:05 PM.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Style based on a design by Essilor
Copyright Top Mud Sites.com 2022