Welcome to the Builder Academy

Question Unable to get resources to save after rent

More
30 May 2022 00:44 #10072 by Nero
I have added resources to my game (lumber, ore) However I am running into a problem getting to store the integer on the player file. If they mine a node or chop down a tree the resource stores on their score sheet. If they rent or the game crashes and then rejoin the resources are back to 0. I have scoured player.c to mirror other things like gold storage or player deaths but it still keeps going back to 0. What am I missing here?
Attachments:

Please Log in or Create an account to join the conversation.

More
30 May 2022 14:25 #10073 by mr514
Did you follow through with making sure your pfdefaults.h is setting up your new data? I recall something to that effect during my first race and kingdom additions... Sorry if I am not helpful, Good luck sir!

Please Log in or Create an account to join the conversation.

More
30 May 2022 19:30 #10074 by Nero
Yeah I have #define PFDEF_STONE 0 and #define PFDEF_WOOD 0 not sure if that is what it is supposed to be but it is the same thing as PFDEF_GOLD

Please Log in or Create an account to join the conversation.

More
30 May 2022 21:30 #10075 by thomas
This is really hard to debug remotely ;)

For the save/load mechanism to function, these places need to be altered:

github.com/tbamud/tbamud/blob/master/src/players.c#L269
Code:
GET_GOLD(ch) = PFDEF_GOLD;
set a default before loading, so you have something reasonable if nothing is found.

github.com/tbamud/tbamud/blob/master/src/players.c#L363
Code:
case 'G': if (!strcmp(tag, "Gold")) GET_GOLD(ch) = atoi(line); break;
In the correct case (this must match the tag - 'G' for 'G'old), see if you find the tag you saved with the value. If so, set the value.

github.com/tbamud/tbamud/blob/master/src/players.c#L646
Code:
if (GET_GOLD(ch) != PFDEF_GOLD) fprintf(fl, "Gold: %d\n", GET_GOLD(ch));
When saving, check if the value equals the predefined. Otherwise, write a tag and the value. Note that this tag must start with an uppercase character and match the loading mechanism above.

To debug whether the save code works, look in the actual save file for your tag. If it's not there and should be, you're not saving correctly. If it's there, it's the loading code that's the problem.

Please Log in or Create an account to join the conversation.

More
31 May 2022 05:09 #10078 by Nero
Thanks, I kind of figured its hard to troubleshoot without seeing the code. This definitely helps though. Looking at the save file it is saving the resource but as soon as the character logs back in, it is deleting it. So something on the load code that is the issue.

Please Log in or Create an account to join the conversation.

More
31 May 2022 05:36 - 31 May 2022 05:37 #10079 by thomas
How does your load code adjustments look, exactly?
Last edit: 31 May 2022 05:37 by thomas.

Please Log in or Create an account to join the conversation.

Time to create page: 0.453 seconds