Unable to get resources to save after rent

  • Nero
  • Nero's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
2 months 1 week ago #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
2 months 1 week ago #10073 by mr514
Replied by mr514 on topic Unable to get resources to save after rent
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.

  • Nero
  • Nero's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
2 months 1 week ago #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
2 months 1 week ago #10075 by thomas
Replied by thomas on topic Unable to get resources to save after rent
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
    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
      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
  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.

  • Nero
  • Nero's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
2 months 1 week ago #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
2 months 1 week ago - 2 months 1 week ago #10079 by thomas
Replied by thomas on topic Unable to get resources to save after rent
How does your load code adjustments look, exactly?
Last edit: 2 months 1 week ago by thomas.

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

  • Nero
  • Nero's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
2 months 1 week ago - 2 months 1 week ago #10080 by Nero
Here is a copy of my players.c file the two resources I am trying to load up are Lumber (GET_WOOD(ch)) and Ore (GET_STONE(ch))
Attachments:
Last edit: 2 months 1 week ago by Nero.

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

More
2 months 1 week ago #10081 by thomas
Replied by thomas on topic Unable to get resources to save after rent
The tags need to be exactly 4 characters long.

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

  • Nero
  • Nero's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
2 months 1 week ago #10082 by Nero
Looks like that was my issue...interesting I feel like I had tried that originally but it now works! Thanks a lot for your knowledge!

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

Time to create page: 0.179 seconds