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
➜ Gold
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| Metsuro
USA (389 posts) Bio
|
Date
| Sun 02 Jul 2006 10:55 PM (UTC) |
Message
| Alright i have 2 questions, first question. In smaugfuss you can only have 2 billion some gold, I was wondering how i might raise the amount to something a bit higher, and something not really dealing with the coding. But which is the best way to like tar something, I am asking cause I want to make backups of my source and i'm not sure how. |
Everything turns around in the end | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Sun 02 Jul 2006 11:27 PM (UTC) |
Message
| The problem is that gold is stored as a single number and numbers can only be so big. There is are several solutions, the easiest of which is simply to use a bigger number format, a long long, which is 64 bits, which is more gold than you could possibly need. Might I suggest, however, if your players need more than 2 billion gold, your system probably suffers from monstrous inflation and it really might not be a good idea to make it worse.
To tar something, the best is probably to write a small shell script like this:
#!/bin/bash
tar -czf my_backup_`date +"%y%m%d"`.tgz my_mud_directory
That will create a file called "my_backup_xyz.tgz" where tgz is the current date in yymmdd format. You would run this script whenever you wanted to create a backup. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Metsuro
USA (389 posts) Bio
|
Date
| Reply #2 on Sun 02 Jul 2006 11:37 PM (UTC) |
Message
| well I am wanting to know also for future reference because we want to setup player run cities/villages that could net more then 2 billion gold and the like. And saddly I am not sure how I would run the script or put it in? not very familiar with linux and the like |
Everything turns around in the end | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Mon 03 Jul 2006 12:44 AM (UTC) |
Message
| Well, the long-long (64-bit integer) is probably your best bet, unless you want to get into more complicated solutions like using two numbers. Still, it seems that your problem is bringing money to villages/cities, not players directly, in which case you can use alternate solutions.
For the script, just make a file called "make_backup.sh" or whatever you want to call it, put in what I gave, make the file executable (chmod +x make_backup.sh ), then run it just like you run your startup script (in this case, by typing ./make_backup.sh ). |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Reply #4 on Mon 03 Jul 2006 12:54 AM (UTC) |
Message
| You could also use unsigned to "double" the max allowed, I think. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #5 on Mon 03 Jul 2006 01:22 AM (UTC) |
Message
| Doubles raise some issues due to floating point precision, where you can have these really, really weird results like 3 not being equal to 5+2-4. (I've seen things like that before, it's quite strange; it depends on how it initializes its values. Basically the problem is that you have 3.000000 != 3.000001). An unsigned 64-bit long can hold 18,446,700,000,000,000,000 values -- any system that gives players that much gold has some serious issues! :-) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Metsuro
USA (389 posts) Bio
|
Date
| Reply #6 on Mon 03 Jul 2006 01:35 AM (UTC) |
Message
| Well my mud will be using groups of people who could all donate to the city or village they are in, raising the vities bank, now if you have like 10-20 members all donating and the like... the values gonna go up and up. I just want to make sure they dont get to much limit on there earning in that regard. |
Everything turns around in the end | Top |
|
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Reply #7 on Mon 03 Jul 2006 01:54 AM (UTC) |
Message
| Rather than doing this, you could also make a new money value. Something like "Gold bars" which equals maybe 100mil in Gold or something. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #8 on Mon 03 Jul 2006 06:37 AM (UTC) |
Message
| The author of Lua claims that double is fine to represent any value up to a long without error or rounding problems.
I quote from chapter 2.3 of the Lua manual:
Quote:
There is a widespread misconception about floating-point arithmetic errors and some people fear that even a simple increment can go weird with floating-point numbers. The fact is that, when you use a double to represent an integer, there is no rounding error at all (unless the number is greater than 100,000,000,000,000). Specifically, a Lua number can represent any long integer without rounding problems. Moreover, most modern CPUs do floating-point arithmetic as fast as (or even faster than) integer arithmetic.
Given that a billion is 1,000,000,000 (thousand million) - and an unsigned long can go as high as 4,294,967,296 (4 billion) then you can go up to a lot higher than a billion with the double type. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #9 on Mon 03 Jul 2006 12:30 PM (UTC) |
Message
| All I can say is that I have had issues where two floating point numbers (less than a thousand) that should have been equal were not, and I had to write a very-near-to-equal function instead. Perhaps I wasn't using them quite correctly, and the mantissa etc. weren't being initialized correctly, or it could even have been a compiler issue, but they truly were not behaving as I had expected.
Of course, there's nothing inherently unstable about the double representation. I didn't mean to imply that. What I meant is that I've had issues that could have been due to any number of things, but pulling out doubles and sticking in longs solved the problem straight away. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #10 on Mon 03 Jul 2006 01:16 PM (UTC) |
Message
| Yes I can believe that. However suddenly I can't reproduce it. For example, using Lua:
print (((1 / 3) * 3) == 1) --> true
I half-expected 1/3 to be something like 0.333333333 which when multiplied by 3 would give 0.999999999, and thus not be equal to 1, however it seems to work. :)
In fact, try this:
a = 1/3
print (a) --> 0.33333333333333
b = a * 3
print (b) --> 1
print (b == 1) --> true
I can't totally explain that behaviour. :)
However you are probably right that a long long will do the trick (up to 1.844674407371e+019 anyway), and if you are going to change the type anyway, long long is probably the way to go. Having said that, for something like a "country" economy, the odd single gold piece that goes missing out of billions probably won't be missed. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #11 on Mon 03 Jul 2006 01:28 PM (UTC) |
Message
| My problem was in C++, I'll have to see if I can find it.
But for your case, I suspect it might be constant propagation. If it's not actually doing the arithmetic every time, and is instead just folding constants around, it would know that 1/3*3 is the same as just 1. It would be interesting to write an interactive-mode script to see if this still worked, but at the moment I have to run off to work. :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Metsuro
USA (389 posts) Bio
|
Date
| Reply #12 on Mon 03 Jul 2006 03:00 PM (UTC) |
Message
| Well using something like long double gold; produces a thing like this.
act_wiz.c: In function `do_mstat':
act_wiz.c:1975: warning: int format, long double arg (arg 6)
and its just vitcim->gold. I've seen in another source (dbsc) which they use a double for exp that they use num_punct() for the problem I have. But even that wont work. |
Everything turns around in the end | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #13 on Mon 03 Jul 2006 03:12 PM (UTC) |
Message
| Well, of course, the printf is expecting an integer, and you've given it a long double. If you really want to use doubles (and again, a long long is probably a much better solution), you need to use the right format specifier. Read up in "man printf " (or "man 3 printf ") for a list of format specifiers. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Metsuro
USA (389 posts) Bio
|
Date
| Reply #14 on Mon 03 Jul 2006 05:07 PM (UTC) |
Message
| alright but see this is from dbsc.
pager_printf_color( ch, "&cYear: &w%-5d &cSecs: &w%d &cTimer: &w%d &cZeni: &Y%s\n\r",
get_age( victim ), (int) victim->played, victim->timer, num_punct(victim->gold) );
and this is from smaugfuss
pager_printf_color( ch, "&cYear: &w%-5d &cSecs: &w%d &cTimer: &w%d &cGold: &Y%d\r\n",
get_age( victim ), ( int )victim->played, victim->timer, victim->gold );
so maybe I'm missing something? |
Everything turns around in the end | 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.
58,524 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top