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

Boring code/math help

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

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 (2KB, 331x31px) Image search: [Google]
20160715064924881.png
2KB, 331x31px
>>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 posts: 9
Thread images: 2


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.