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
➜ Math/logic, transfer vars
|
Math/logic, transfer vars
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Sat 28 Jul 2007 06:41 PM (UTC) |
| Message
| This is somewhat complicated, so I'll try my best without having to explain everything.
A player has two variables, var1 and var2. There is a command that transfers from var1 to var2. The player picks the amount to transfer, and it is done over time. If they transfer 100% of var, it takes 10 rounds. 50% is 5 rounds, etc.
Since it takes time, obviously we need to store some temp variables. I'm looking to do this by using the least amount of variables.
Currently, I'm using two temp variables (var3 which stores the amount left to transfer, and var4 which stores how long it'll take. But these don't work correctly. The transfer will sometimes end but it hasn't transferred the correct amount (it cut short).
Would there be a better var to store instead of var3 and var4 so that this problem would be fixed? |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| Conner
USA (381 posts) Bio
|
| Date
| Reply #1 on Sat 28 Jul 2007 07:01 PM (UTC) Amended on Sat 28 Jul 2007 07:03 PM (UTC) by Conner
|
| Message
| ok, so Mr(s). Player has X of something and chooses to transfer some or all of that to Y which will take T rounds based on how large a percentage of X (s)he wants to transfer to Y but during those ensuing T rounds (s)he may gain additional X so your storing the quantity of X to be transferred in Z and each round transferring some of 10% of X to Y by subtracting it from the player's X and Z, adding it to their Y and subtracting one from T, but it's not always transferring all of Z to Y before T runs out?
Would it be better to store their full X as Z when the transfer begins and then each round reduce T by one, reduce X by Z*0.1 and increase Y by Z*0.1 so that when T=0 the transfer is complete regardless and then you can just reinitalize Z?
Or have I just blown this all out of algebraic proportions on you? ;) |
-=Conner=-
--
Come test your mettle in the Land of Legends at telnet://tcdbbs.zapto.org:4000
or, for a little family oriented medieval fun, come join us at The Castle's Dungeon BBS at telnet://tcdbbs.zapto.org
or, if you just want information about either, check our web page at http://tcdbbs.zapto.org | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #2 on Sat 28 Jul 2007 07:43 PM (UTC) |
| Message
| Well, yes a player will transfer an amount (they do not choose a percent though) from X to Y which takes T rounds. I'm not sure what Z is. var3 and var4 are temp variables used solely to accomplish the transfer.
I don't think we could reduce X by Z*0.01 either, because what if they were only transferring 1? (Not the percent) |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Sat 28 Jul 2007 09:25 PM (UTC) Amended on Sat 28 Jul 2007 09:26 PM (UTC) by Nick Gammon
|
| Message
| I think I would store the amount left to transfer, and the amount to transfer each time. I assume you are doing it at a fixed interval. Based on the player input you would set how much to transfer per tick (or whatever the interval is). The total amount starts "full" initially.
Then each tick, you transfer more of the amount left over, until it runs out, with a possible half transfer at the end.
Something like this:
amount_to_transfer = amount_per_tick; // tick amount
if (amount_to_transfer > amount_left) // don't do more than max
amount_to_transfer = amount_left;
amount_left -= amount_to_transfer; // less next time
var1 -= amount_to_transfer; // move from var1 to var2
var2 += amount_to_transfer;
if (amount_left <= 0)
{
// done
}
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Conner
USA (381 posts) Bio
|
| Date
| Reply #4 on Sun 29 Jul 2007 03:57 AM (UTC) |
| Message
| | Sorry Zeno, my Z variable was the other temp variable besides number of rounds, but I was operating under the impression they got to choose only the percentage of X to be transferred in incriments of 10%. |
-=Conner=-
--
Come test your mettle in the Land of Legends at telnet://tcdbbs.zapto.org:4000
or, for a little family oriented medieval fun, come join us at The Castle's Dungeon BBS at telnet://tcdbbs.zapto.org
or, if you just want information about either, check our web page at http://tcdbbs.zapto.org | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #5 on Sun 29 Jul 2007 07:52 PM (UTC) |
| Message
| | Thanks Nick, that worked out fine. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | 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.
20,355 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top