- Home /
Terribly explained ... Trying a new question.
Log a quickly changing value without boolean flags
Hey there,
This may seem like a simple question, but this is the only way I've found to do it. Is there a way to capture a quickly changing value (such as a Random.Range or a Time.deltaTime) at a specific point in time without using boolean flags in an arrangement like this?
if (boolFlag) {
varForLogging = Random.Range(0, 800);
boolFlag = false;
}
It seems as if there should be an easier way to log values than this, however I haven't been able to find any other solutions for this. Don't get me wrong, this works fine, I'd just like to know if this is in fact the best for solution for capturing values.
Thanks for your time,
Klep
Not quite sure what the deal is here. Why don't you call a function that logs the value directly? Could you explain a little further what is going on here? What's wrong with using 'Debug.Log'? Also, Random.value doesn't change until you call it (because every call to 'Random' changes the seed).
Sorry if I wasn't very clear. I'm not talking about debugging here, I'm talking about ins$$anonymous$$d capturing the value of a quickly changing class such as Time.deltaTime at an exact frame and not having that variable continue to change as Time.deltaTime changes. For example, in one frame Time.deltaTime might be 0.56 and then in the next frame might change to 0.76. I want to capture that 0.56 in a variable and not have it change to 0.76 as Time.deltaTime continues to change. The only way I've found to do this is to have a boolean automatically negate itself, however I know that this mustn't be the best way of doing things.
Here is a working example of what I mean here:
if (clockStop == 1) {
if(!hasStopped) {
stopTime[ts.$$anonymous$$inute] = gt.currentTime;
stopTime[ts.Hour] = gt.currentTime;
hasStopped = true;
}
}
currentTime is a time variable which is incremented in another script by Time.deltaTime * rate. I want to find the exact "currentTime" at the moment an int becomes 1. However, if I were to do this without the boolean flags, stopTime[ts.$$anonymous$$inute] and stopTime[ts.Hour] would continue to increment as currentTime increments. I'm sure there must be a more elegant solution than this, because it seems very hacky to me.
Just to clarify, I only found this solution originally here from @DaveA.
So sorry if this has made things a hell of a lot more confusing ...
Thanks for your help anyway @syclamoth :)