chiro said:
This means you need to check every 1/framerate times per second if you update the framerate variable every second.
yes i know that. i already have an event that triggers once per frame, that i do a lot of work in. I'm not updating the framerate every second though. it'll be just an occasional thing. but i have a global variable for the framerate which is incorporated into most calculations in the engine (the variable is actually 1/framerate). if i modify the framerate, i'll change that too.
What will help me clarify what you want to do, is to tell me what the value should be at point a, what it will be at point a + t (t could be 1 second, or it could be based on some formula) and what you want in-between.
i think i mentioned that:
To make it clear, I'm looking for a compound reduction here. ie the sequence after 0, 1, 2, 3 seconds etc, would be 100, 95, 90.25, 85.735, 81.45, etcetera.
that assumes a starting value of 100 and a reduction of 5%
My example did compound the result because after each event x was modified. This means if 30 events were processed in the space of a second, then after a second x = x_int x (0.95)^30 where x_int is the initial value since the process gets called 30 times (1 time each event for 30 events).
ah i misread, my bad. But no, that's not what i want to do. With a reduction value of 5%, i want to end up at 95
after one second. I want to knopw how to figure out what value to multiply it by
each frame so that it will end up decreasing by 5% each second
The reason why events are good is because this kind of thing is easy. Also you should realize most modern engines have a very comprehensive event system (just so you know I used to be a games programmer) so it would be worth your while to think about this.
yes i know, i;m using events. I think we misunderstood each other. my issue with your approach was simply that it was updating the value once per second. I want to update it f times per second.
just so there's no misunderstanding here, let me clarify the variables involved:
n: a value i want to reduce. in this example, n = 100
p: The percentage i want to reduce it by. in this case p = 0.95 to represent a 5% reduction
f: the framerate of the program - how many times we're going to be updating the value each second. in this example, f = 30
Frame 0: n = 100
frame 1: n = ?
...
...
frame 30: n = 95
...
...
frame 60: n = 90.25
What value should i multiply n by in frame 1? can i work out a value to repeatedly multiply n by, so that it will be 95 by the time we've done the multiplication 30 times?
let me also make it clear that I'm aware that i can do this to calculate n for any arbitrary frame x:
=n * p^(x*(1/f))
but that is not what i want to do, because i don't want to have to track x. this may well be more efficient or simpler, but it's NOT what i want to do.
do we understand each other now ?