Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ Possible File I/O Problem
Possible File I/O Problem
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
Posted by
| Trom
(82 posts) Bio
|
Date
| Reply #15 on Mon 09 Feb 2004 04:56 PM (UTC) Amended on Mon 09 Feb 2004 04:59 PM (UTC) by Trom
|
Message
| The below are fragments from the functions that deal with the classes in my mud. When it comes to reading a class in load_char_obj, it checks to see if its null so it doesn't re-empty it (since there would be no need too), if its not null it scans to the end of the classes and makes space to add another, than moves to fread_class().
load_char_obj:
ch->classes = new_classes ( );
CLASS_DATA *cls = ch->classes;
sprintf ( strsave, "%s%s", PLAYER_DIR, capitalize ( name ) );
if ( ( fp = file_open ( strsave, "r" ) ) != NULL )
{
int iNest;
for ( iNest = 0; iNest < MAX_NEST; iNest++ )
rgObjNest[iNest] = NULL;
found = TRUE;
for ( ;; )
{
char letter;
char *word;
letter = fread_letter ( fp );
if ( letter == '*' )
{
fread_to_eol ( fp );
continue;
}
if ( letter != '#' )
{
bug ( "Load_char_obj: # not found.", 0 );
break;
}
word = fread_word ( fp );
if ( !str_cmp ( word, "PLAYER" ) ) {
fread_char ( ch, fp );
}
else if ( !str_cmp ( word, "OBJECT" ) || !str_cmp ( word, "O" ) ) {
fread_obj ( ch, fp );
}
else if ( !str_cmp ( word, "CLASS" ) ) {
if (cls != NULL) {
while (cls != NULL)
cls = cls->next;
cls = new_classes( );
}
fread_class ( cls, fp );
}
else if ( !str_cmp ( word, "PET" ) ) {
fread_pet ( ch, fp );
}
else if ( !str_cmp ( word, "END" ) )
break;
else
{
bug ( "Load_char_obj: bad section.", 0 );
break;
}
}
file_close ( fp );
}
This is fread_class()
void fread_class ( CLASS_DATA *cls, FILE * fp )
{
char *word;
bool fMatch;
int temp = 0;
for ( ;; )
{
word = feof ( fp ) ? "End" : fread_word ( fp );
fMatch = FALSE;
switch ( UPPER ( word[0] ) )
{
case '*':
fMatch = TRUE;
fread_to_eol ( fp );
log_string("fread_class: *");
break;
case 'L':
fMatch = TRUE;
if ( !str_cmp( word, "Level" ) ) {
temp = fread_number ( fp );
cls->level = temp < 1 ? 1 : temp;
}
break;
case 'I':
fMatch = TRUE;
if ( !str_cmp( word, "Id" ) ) {
temp = fread_number ( fp );
cls->id = temp < 0 ? 0 : temp;
}
break;
case 'E':
if ( !str_cmp ( word, "End" ) )
return;
break;
}
if ( !fMatch )
{
bug ( "Fread_class: no match.", 0 );
fread_to_eol ( fp );
}
}
return;
}
Without the use of temp, the values would be put into the files directly as -1, which would probably crash the mud when it tries to lookup -1 in the class tables (class_table[-1]), until it works i'm going to keep that in.
new_classes() is a function like new_pcdata(), it assigns a default value of -1 to level and id of the class and before that alloc_mem() so it won't crash the mud when its referenced.
| Top |
|
Posted by
| Greven
Canada (835 posts) Bio
|
Date
| Reply #16 on Mon 09 Feb 2004 06:36 PM (UTC) |
Message
| So the only place that its set to -1 ever is in new_classes? Then it looks like its being called somewhere after the class is read. Have you tried to set a breakpoint on it and see when its called? |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | Top |
|
Posted by
| Trom
(82 posts) Bio
|
Date
| Reply #17 on Mon 09 Feb 2004 07:53 PM (UTC) |
Message
| C:\cygwin\home\doe15\src\finger.c(81): victim->classes = new_classes ( );
C:\cygwin\home\doe15\src\recycle.c(552):CLASS_DATA *new_classes ( void )
C:\cygwin\home\doe15\src\recycle.h(112):CC *new_classes args ( ( void ) );
C:\cygwin\home\doe15\src\save.c(681): ch->classes = new_classes ( );
C:\cygwin\home\doe15\src\save.c(771): cls = new_classes( );
Did that in visual c and checked all of them, nothing that would cause a prob. I'm starting to wonder if this problem is possible to solve. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #18 on Mon 09 Feb 2004 08:38 PM (UTC) |
Message
| You are doing the same thing, but in a different way ...
ch->classes = new_classes ( );
CLASS_DATA *cls = ch->classes;
...
if (cls != NULL) {
while (cls != NULL)
cls = cls->next;
cls = new_classes( );
}
fread_class ( cls, fp );
You are still changing the copy, not the original. This line:
cls = cls->next;
is only changing your local copy of the cls field.
Why bother with a copy? Get rid of the line:
CLASS_DATA *cls = ch->classes;
Then use "ch->classes" instead of "cls" in the function.
However I think it looks complicated. I would have had:
void fread_class ( CHAR_DATA * ch, FILE * fp )
{
...
}
And inside fread_class simply referred to ch->classes.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Trom
(82 posts) Bio
|
Date
| Reply #19 on Mon 09 Feb 2004 09:23 PM (UTC) |
Message
| If i use ch->classes, i won't be able to return to the start of the list. ch->classes is the list, if i traverse that list, then theres no way of returning to the start of it. What i want to do is a make a copy of it so that anything modified to that is modified in the true classes, but since its not actually it, i could use it anytime making pointers.. Basically i don't see how i can get the first ch->classes data if its assigned directly.
ch->classes = new_classes()
ch->classes->level = fread_number(fp);
ch->classes = ch->classes->next;
ch->classes->level = fread_number(fp);
how would you see the first node if you did it that way.. I'm probably misunderstanding. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #20 on Mon 09 Feb 2004 11:42 PM (UTC) |
Message
|
CLASS * cls = new_classes ();
if (ch->classes)
ch->classes->next = cls;
else
ch->classes = cls;
There is a difference. This method changes the actual class list. Your method changed "cls" but not "ch->classes".
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Trom
(82 posts) Bio
|
Date
| Reply #21 on Tue 10 Feb 2004 03:04 PM (UTC) Amended on Tue 10 Feb 2004 03:19 PM (UTC) by Trom
|
Message
| Thanks, i got it working using that method you showed previously. | 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.
59,032 views.
This is page 2, subject is 2 pages long:
1
2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top