[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Boring code/math help
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 9
Thread images: 2
Okay, I know this isn't sci so I don't know how many math experts hang around these parts, but I need some help. Bare with me, I have diagnosis-able brain problems when it comes to math stuff, so I'm a bit stumped here.

I have this shitty game thing I'm working on and I need to figure out how to process an effect that scales with the stat it effects over time.

So lets say x is health or something, like 100 hp and the effect adds 25% of x to x each minute. I want to pass 3 minutes or something

This works fine if I interval the equation each minute that passes, like below
given that x = 100
1: x += (x *0.25) = 125
2: 125 += (125*0.25) = 156.25
3: 156.25 += 156.25*0.25 = 195.312

So there's that, but I don't want to interval through each minute of time that's passed. say its 1440 minutes or something, I don't want it to cycle each time, I want a single equation but how do I write it so it just scales for a time variable

obviously if t = 3 and x = 100
x += (x*0.25)* (t) = 175
and that's not the same outcome as doing the equation 3 times, so my math-dead brain is stuck
>>
>>156241
Sounds like compounding interest.
x = P(1+(r/n))^nt
P = initial amount = 100
r = interest rate = .25 (25%)
t = total time = 1440 minutes
n = compounds every t = 1 since you want it every minute
>>
>>156253
With everything plugged in we get:

x = 100(1.25)^t
>>
>>156253
>>156255
Thanks for the feedback!
It doesn't really do what I expect it to though.

The ordinary add (x*0.25) to x above ends up at 195.312 after 3 times, but when I run this I end up with 126 when t = 3
>>
File: 20160715064924881.png (2 KB, 331x31) Image search: [Google]
20160715064924881.png
2 KB, 331x31
>>156263
I'm not sure how you achieved that, but it worked fine for me.
>>
>>156266
oh, huh
I did this
N = 100;
T = 3;
N = (N*(1+(0.25/1)))^T;

Whats that "for x in range(4)" part mean? Sorry for my ignorance, I'm pretty new to code math
>>
>>156274
It was just a way for me to test for x = {0,1,2,3} in my equation (In this case, x was time).
In your equation you're raising everything by t, but only the (1 + .25/1) needs to be raised by t.
>>
>>156274
Oh well that's one thing, but I also realized ^ was a short cut for a binary xor operator, not exponential. Had to use "Math.Pow()"

Works fantastically now. Thanks a lot anon.
>>
>>156280
Glad it worked out.
Thread replies: 9
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.