Welcome to the Builder Academy

Question Saving/loading variables over 2.1billion

More
25 Oct 2015 22:47 #5520 by Liko
Hello,

sorry been gone awhile, health hasn't been the best. I have had issues with this in the past and haven't been able to fix it at all. How would I be able to get a variable to save and load over 2.1 billion of a number. I have tried long and long long. Nothing.

- Liko

Randian(0.0.0)
Owner/Developer

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

More
26 Oct 2015 21:35 #5521 by thomas
long long is correct (upper bound of long is 2.1 billion, for long long it's 9*10^18 or close to - en.wikipedia.org/wiki/C_data_types ).

To save and load with this, use the format specifier %lli in sprintf and sscanf.
The following user(s) said Thank You: Liko

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

More
29 Oct 2015 00:36 - 29 Oct 2015 00:37 #5522 by Liko
Okay, thank you :). That solved that error. Now I have a small one.

I wanted to increase the modifier, but i get this error:

structs.h, its fine if I have it at 2.1b
Code:
#define MAX_KILI 2140000000 /* Maximum kili*/

lets say I add two zeroes, I get this warning:
Code:
#define MAX_KILI 2140000000000 /* Maximum kili*/
Code:
limits.c: In function ‘increase_kili’: limits.c:643:17: warning: overflow in implicit constant conversion [-Woverflow] GET_KILI(ch) = MIN(MAX_KILI, curr_kili+amt); line: 643 GET_KILI(ch) = MIN(MAX_KILI, curr_kili+amt);

So I think I did something wrong? Did I not change a variable? Does it have something to do with the actual #define? What do I have to increase for it to support over 2.1b?

Randian(0.0.0)
Owner/Developer
Last edit: 29 Oct 2015 00:37 by Liko.

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

More
29 Oct 2015 21:56 #5523 by thomas
MIN is a function working on ints:
<code>
/* undefine MAX and MIN so that our functions are used instead */
#ifdef MAX
#undef MAX
#endif

#ifdef MIN
#undef MIN
#endif

int MAX(int a, int b);
int MIN(int a, int b);
</code>
You could refactor it to use long long instead, or make a different version for this purpose.
The following user(s) said Thank You: Liko

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

More
30 Oct 2015 16:30 #5524 by Liko

thomas wrote: MIN is a function working on ints:
<code>
/* undefine MAX and MIN so that our functions are used instead */
#ifdef MAX
#undef MAX
#endif

#ifdef MIN
#undef MIN
#endif

int MAX(int a, int b);
int MIN(int a, int b);
</code>
You could refactor it to use long long instead, or make a different version for this purpose.


I knew it was something like that! I was just looking for the file :). Silly me.

Randian(0.0.0)
Owner/Developer

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

More
01 Nov 2015 22:37 #5527 by Liko
So I installed a fresh tbamud, used %lli for the variables for "powerlevel" and it still will not save or load anything over 2.1b. I just can't figure it out. I've done everything that has been suggested.

Randian(0.0.0)
Owner/Developer

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

Time to create page: 0.198 seconds