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
➜ SMAUG
➜ SMAUG coding
➜ 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 page
Pages: 1
2 3
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #15 on Tue 03 Jul 2007 12:20 AM (UTC) |
| Message
|
Quote: That's why I'd rather save them by something else. They are saving as skill numbers right now. The reason being once I added a new skill/spell all numbers would be off in the mem list.
So, you are writing out skill numbers, BUT you would rather save them as spell names?
In that case, you can just emulate the code you posted from character reading/saving that translates from names to numbers etc.
Quote: When you save I believe this is what writes out the 100 0's because max_mem_spell is 100, they can't mem anymore then that.
No, that just writes whatever is in those arrays. If you don't set them to zero explicitly when you create the character structure, you will be writing out whatever contents of memory happen to be in that array. (Arrays are not initialized to zero when you create them.) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #16 on Tue 03 Jul 2007 12:25 AM (UTC) Amended on Tue 03 Jul 2007 12:36 AM (UTC) by Orik
|
| Message
|
Quote:
So, you are writing out skill numbers, BUT you would rather save them as spell names?
In that case, you can just emulate the code you posted from character reading/saving that translates from names to numbers etc.
yes, I would rather change them to names. So I might need a little help figuring out how to emulate the skill fread/fwrite. I'll work on that and see if I can come up with something and post it.
Quote:
No, that just writes whatever is in those arrays. If you don't set them to zero explicitly when you create the character structure, you will be writing out whatever contents of memory happen to be in that array. (Arrays are not initialized to zero when you create them.)
Not sure. I never get any bugs when I create a new character. I'll have to look into it more. When I ported it over from Envy it was late at night and a blur...lol.
**********EDIT *********
I'm not sure how I can write and read the mems. Everything I try isn't right. | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #17 on Tue 03 Jul 2007 12:43 AM (UTC) Amended on Tue 03 Jul 2007 01:25 AM (UTC) by Orik
|
| Message
| How bout this:
for (j = 0; j < MAX_MEM_SPELLS; j++)
for (sn =1; sn < top_sn; sn++)
if( skill_table[sn]->name > 0)
fprintf(fp, "Memorized: %d '%s'\n", j, skill_table[sn]->name );
for (j = 0; j < MAX_MEM_SPELLS; j++)
for (sn =1; sn < top_sn; sn++)
if( skill_table[sn]->name > 0)
fprintf(fp, "Memorizing: %d '%s'\n", j, skill_table[sn]->name );
*****edit *****
That didn't work. It wrote out every skill/spell 100 times...lol
***************************
2nd attempt
***************************
for (j = 0; j < MAX_MEM_SPELLS; j++)
for (sn =1; sn < top_sn; sn++)
if( skill_table[sn]->name && ch->pcdata->memorized[j])
fprintf(fp, "Memorized: %d '%s'\n", j, skill_table[sn]->name );
for (j = 0; j < MAX_MEM_SPELLS; j++)
for (sn =1; sn < top_sn; sn++)
if( skill_table[sn]->name && ch->pcdata->memorized[j])
fprintf(fp, "Memorizing: %d '%s'\n", j, skill_table[sn]->name );
This is a no go. It just wrote out all skills for 0. So it didn't get to go back through the first for loop.
***************************
3rd attempt
***************************
for (j = 0; j < MAX_MEM_SPELLS; j++)
for (sn =1; sn < top_sn; sn++)
if( skill_table[sn]->name && ch->pcdata->memorized[j] && ch->pcdata->learned[sn] > 0 && skill_table[sn]->type == SKILL_SPELL)
fprintf(fp, "Memorized: %d '%s'\n", j, skill_table[sn]->name );
for (j = 0; j < MAX_MEM_SPELLS; j++)
for (sn =1; sn < top_sn; sn++)
if( skill_table[sn]->name && ch->pcdata->memorized[j] && ch->pcdata->learned[sn] > 0 && skill_table[sn]->type == SKILL_SPELL)
fprintf(fp, "Memorizing: %d '%s'\n", j, skill_table[sn]->name );
This one prints out each spell for each j loop.
IE: I type
mem heal
mem dispel magic
mem vitality
it saves as
Memorized: 0 'heal'
Memorized: 0 'dispel magic'
Memorized: 0 'vitality'
Memorized: 1 'heal'
Memorized: 1 'dispel magic'
Memorized: 1 'vitality'
Memorized: 2 'heal'
Memorized: 2 'dispel magic'
Memorized: 2 'vitality'
So it's not going through the for loop correctly. It should read:
Memorized: 0 'heal'
Memorized: 1 'dispel magic'
Memorized: 2 'Vitality' | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #18 on Tue 03 Jul 2007 01:24 AM (UTC) |
| Message
| I haven't tried this, but this is closer to what you want:
for (j = 0; j < MAX_MEM_SPELLS; j++)
{
int sn = ch->memorized[j];
if( skill_table[sn]->name != 0)
fprintf(fp, "Memorized: %d '%s'\n", j, 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: %d '%s'\n", j, skill_table[sn]->name );
}
|
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #19 on Tue 03 Jul 2007 01:33 AM (UTC) |
| Message
| Ok, that works, but it's showing all the 0 sn's as reserved.
Example:
I memed heal, dispel magic, and vitality
Pfile looks like this:
Memorized: 0 'heal'
Memorized: 1 'dispel magic'
Memorized: 2 'vitality'
Memorized: 3 'reserved'
Memorized: 4 'reserved'
Memorized: 5 'reserved'
Memorized: 6 'reserved'
...
Memorized: 99 'reserved'
Memorizing: 0 reserved
Memorizing: 1 reservedmagic'
Memorizing: 2 reserved
Memorizing: 3 'reserved'
Memorizing: 4 'reserved'
Memorizing: 5 'reserved'
Memorizing: 6 'reserved'
...
Memorizing: 99 'reserved'
| | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #20 on Tue 03 Jul 2007 01:42 AM (UTC) Amended on Tue 03 Jul 2007 02:30 AM (UTC) by Orik
|
| Message
| Ok, added the && ch->pcdata->learned[sn] > 0 to it and it works perfect now.
Now for the fread part. Be back in a minute for an update on that.
if( !strcmp( word, "Memorized" ) )
{
int sn, value;
if( preload )
word = "End";
else
{
value = 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." );
else
{
ch->pcdata->learned[sn] = value;
if( ch->level < LEVEL_IMMORTAL )
if( skill_table[sn]->skill_level[ch->Class] >= LEVEL_IMMORTAL )
{
ch->pcdata->learned[sn] = 0;
ch->practice++;
}
}
fMatch = TRUE;
break;
}
}
if( !strcmp( word, "Memorizing" ) )
{
int sn, value;
if( preload )
word = "End";
else
{
value = 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." );
else
{
ch->pcdata->learned[sn] = value;
if( ch->level < LEVEL_IMMORTAL )
if( skill_table[sn]->skill_level[ch->Class] >= LEVEL_IMMORTAL )
{
ch->pcdata->learned[sn] = 0;
ch->practice++;
}
}
fMatch = TRUE;
break;
}
}
What exactly does that preload mean?
********EDIT********
The above code isn't working. It's bugging out and won't read the pfile correctly. Will try again with something else soon.
********************
I believe it's the
if( preload )
word = "End";
that's causing the problem. Here's the bug:
FILE: ../player/g/Greg LINE: 50
BUG: fread_char: no match: End
and it does that for all three spells I memed.
*********************
3rd attempt
*********************
I took out the if (preload) statement. I didn't get any errors but it always deleted my memorized spells so I'd mem the spells, log out, log back in and have nothing. | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #21 on Tue 03 Jul 2007 02:48 AM (UTC) Amended on Tue 03 Jul 2007 03:08 AM (UTC) by Orik
|
| Message
| Ok, I'm down to this:
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;
}
}
I get this bug:
FILE: ../player/g/Greg LINE: 50
BUG: Fread_char: unknown spell.
FILE: ../player/g/Greg LINE: 50
BUG: Fread_char: no match: heal
I get that in both preloading and loading player data
*****************
EDit
*****************
I know I have to get the for loop in there of max mem spells. I'm not sure how to fit it in.
*****************
EDIT 2
*****************
Then again, the spell fread didn't have any for loops in it. I'm just trying to convert the spell into an sn right now. hmm.... | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #22 on Tue 03 Jul 2007 05:09 AM (UTC) |
| Message
| Anyone have any thoughts on this? I'm stumped.
This has got to be the line that's the culprit:
sn = bsearch_skill_exact( fread_word( fp ), gsn_first_spell, gsn_first_skill - 1 );
It must not be reading it properly. | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #23 on Tue 03 Jul 2007 05:21 AM (UTC) |
| Message
| | I'm not sure that's the problem. I think that by trying to abort too early on preload, you might be mixing up the reading function. I would try to get things to work for now, and only try to be clever and optimize later. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #24 on Tue 03 Jul 2007 05:25 AM (UTC) Amended on Tue 03 Jul 2007 05:32 AM (UTC) by Orik
|
| Message
| So what do you suggest? What does it mean to preload or abort to early?
************************************
Quote:
I'm not sure that's the problem. I think that by trying to abort too early on preload, you might be mixing up the reading function. I would try to get things to work for now, and only try to be clever and optimize later.
I am trying to get this to work. I don't know how to optimize lol. Just trying to get it to work and trying everything possible. Been at this forever. | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #25 on Tue 03 Jul 2007 05:40 AM (UTC) |
| Message
| What about something like this:
if ( @strcmp( word, "Memorized" ))
{
int sn;
char *sname;
if( preload )
{
fMatch = TRUE;
fread_to_eol( fp );
break;
}
if (sn = skill_lookup(sname)) < 0)
{
bug( "Fread_char: unknown spell %s.", sname );
}
fMatch = TRUE;
break;
}
This doesn't work but am I on the right track? or should I go with what I had and figure that our more? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #26 on Tue 03 Jul 2007 07:01 AM (UTC) |
| Message
|
Quote:
if( !strcmp( word, "Memorized" ) )
{
int sn;
sn = bsearch_skill_exact( fread_word( fp ), gsn_first_spell, gsn_first_skill - 1 );
I don't see how this is going to work, seeing as you had a number before the spell name.
Remember, gdb is your friend. Try putting a breakpoint on that part of the function and seeing what it is doing. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #27 on Tue 03 Jul 2007 04:37 PM (UTC) Amended on Tue 03 Jul 2007 04:40 PM (UTC) by Orik
|
| Message
| aha! So if I take out that first number to begin with then it should read the word with fread_word? I don't really need that number anyways, it was more for testing purposes.
****EDIT****
and if I did want to keep that number in there, I'd put something like:
int value;
value = fread_number(fp)
and that would read the number first, then put the bsearch after that and that would read the word second? | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #28 on Tue 03 Jul 2007 07:56 PM (UTC) |
| Message
| | Yes, if you have the number there you would need to remove it one way or the other, either by not writing it or by reading it. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Orik
USA (182 posts) Bio
|
| Date
| Reply #29 on Tue 03 Jul 2007 08:11 PM (UTC) |
| Message
| | awesome. I'll get home and try this after work. Thanks David and Nick. | | 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.
131,457 views.
This is page 2, subject is 3 pages long:
1
2 3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top