This week's book giveaway is in the OCAJP forum.We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!

# period rate

Fernando hiar
Greenhorn
Posts: 29
I have a doubt about the period rate, I buy a book Killer programming game in java and I don´t understanding about the period what value i have in period in this formula - Sleeptime = period - timediff - oversleeptime, I know the value of sleeptime, i know the value about the timediff and i know the value of oversleeptime, but i don´t have the value of period, how can i found this value - i know the period is the same fps in ms.

thanks,

Fernando.

fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
ummm....

S = P - T - O

you say you know the value of three of the four. Basic algebra lets you find the last. At 'T' and O to both sides:

S + T + O= P - T + T- O + O

S + T + O = P.

Fernando hiar
Greenhorn
Posts: 29
I know this formula, but this book put a condition if sleeptime > 0 so the timediff took a longer time , how can i say if the sleeptime is negative if i don´t know the period : sleeptime = period - timediff - oversleeptime. I don´t know the value of period, how can i know sleeptime become negative?

thamks,

Fernando.

fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
maybe i'm just not understanding what you're asking... but...

S = P - T - O

is the same as

S = P - (T+O)

From here, it should be easy to see that S will be negative if (T+O) is greater than P.

Now, if you only have one equation with four variables, you CAN'T solve it if you only know the value of 2 of them. You have to have at least one equation for each unknown variable.

Fernando hiar
Greenhorn
Posts: 29
So.....
Are you trying to ask me is when sleeptime > or < 0 the program knows the value of period period = sleeptime + timediff + oversleeptime or the program knows if timediff take a long time the sleeptime becomes negative even don´t know the value of period? It is i want to know I understood what you teaching me, but still stay this doubt.

thanks,

Fernando.

Brian Legg
Ranch Hand
Posts: 488
Fernando, You'll get your answer a lot faster if you posted a small piece of code so we can see exactly where the problem is. I'm still having a hard time figuring out what variables you know the value of, which ones you don't, and what the problem is exactly. Please post some code and put a comment in as to where you should be getting a value that you can't seem to get.

fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
going back to your original post, you said this:

Sleeptime = period - timediff - oversleeptime, I know the value of sleeptime, i know the value about the timediff and i know the value of oversleeptime, but i don´t have the value of period

I took this to mean you have this formula:

Sleeptime = period - timediff - oversleeptime

You then said you "know the value of sleeptime", and that you "know the value of oversleeptime".

I'm not sure what you mean by you "know the value about the timediff" - it's that word 'about' that is confusing. do you know the value of timediff or not?

If you DO know it, getting the value of period is trivial.

If you DO NOT know it, you CAN'T get the value of period without more information.

Fernando hiar
Greenhorn
Posts: 29
I want to know one thing, if i have the value of all variables less one the period sleeptime = period - timediff - oversleeptime, the jvm can get the period value and use this value and each cycle???

thanks,

Fernando.