Played a day around whyte counters and i have to say, it was a little weird to me finding out a little thing about it. FPS based counters are a pain for obvious reasons, so i tried to a classic time dependent function. As for the little SoundTestCar clock i used its time aspect:
// clock
var time = new Date();
var hourrad = time.getHours() * HOURS2RAD;
var minsrad = time.getMinutes() * MIN2RAD;
var secsrad = time.getSeconds() * SEC2RAD;
var hour = time.getHours();
var mins = time.getMinutes();
var secs = time.getSeconds();
var vmin
var SecTime
vmin = 0
//Fuel system script
if (this.started) { // Start counting when engine is on
var secsEl = secs
if ( secsEl = 59 ) {
vmin = ( vmin + 1 )
}
SecTime = ( secs + ( vmin * 60 ) );
ElSec = ( SecTime )
secsS = ( 0 + ElSec );
NeutralConsum = ( secsS * ( ( ( 1 / 300 ) ))) // * 35 ) / 360 ) ); // Consumption on neutral ( IDEAL consumption is about 35 l/h )
IdealConsum = ( NeutralConsum * 1.2 );
Fuel = ( FuelInitial - IdealConsum ); // Actual fuel load ( remember Ural has 300 l and needle rotation 1 !! )
if ( Fuel < 0.034 ) {
secsS = 0;
Fuel = 0;
}
//Fuel needle
this.geom.rotate_joint_orig(this.fuelmeter, Fuel, {x:0, y:1, z:0});
}
//End of fuel system script
... yes, i know the seconds correspond to the actual system state (so it wont go from zero up, but from actual time seconds and only to 59, periodically - so dont mind that little fact right now in there). My test was doe in other thing - wanted to use the vmin variable to change every time, the seconds hit 59 so i do an imaginary minute counter, doe it seems it just increasing the value once and only for the 59-th second. All this script is in the FPS part script ( function update_frame(dt, engine, brake, steering) ). Is it because the " vmin = 0" being there too, setting it allways to 0 again for every frame coming afterwards ? (that is, should i put it somewhere like the once for vehicle instance section, or have the whole thing rather in function action(k,v,dt) section ?) Yes, i should probably use an "else" addition to the "if" too and in a little more thought order.
Also the puzzling part for me is time definition in java - There isnt a way to simply define a second time-frame, and you have to find a way to calculate a second (minute, hour etc.) trough actual time differences or make a counter like - ActualTime(in seconds) - SomeInitialTime(in seconds). Now you can set the actual time, but i cant find a way to take an "instant time" (just the static time of something happening - like engine start) to add it to that thing. Seen somewhere a way of "profiling" times in an pause-able counter (liked to use that for the engine-code to stop it every-time you turn off the engine and make some RPM and Gear dependent consumption functions there), doe some of the methods ("Calendar.", "long" etc) werent recognized. Im not sure if there has to be an other approach like the "Timer" discussed on the end here :
http://java.ittoolbox.com/groups/technical-functional/java-l/java-code-a-counter-which-increments-by-1-every-second-2675231 - where it seems i would have to add that to some folder in OT and load it at begining of the script just like Aircraft-scripts have it - if im not wrong.
Small time-chunks can be done whyte the clock-data too, but for something time-consuming as fuel consumption calculator its a little too short or odd ways done (just like a "freeze" type counter approach would need to have the freeze-milisecond sequence postponed the proces and waiting 120 secs to have enough counter-time for the script i need is something rather odd).
Im stagged that there isnt something like a real simple time-definition. Doe, i also got an other approach idea - maybe i could use the OT time and date data - just need a way to get actual time (just like the clock up posted there ) and a fixed time in specific moment. This approach would be maybe more interesting, as the vehicle stuff could be synched to the OT time-flow and simulations in slower or faster time-flow as the real world could be done just by simple movement of the multiplier bar in the environment options. (would be also perfect to check if the consumption-calculations in script are consistent whyte reality easily too) Is there a wiki-page or a way to get those time-data from the engine ? (think it will be needed to mark specific in-Engine time-events for folks too - i might missed a talk about that or being just blind and scripting under-knowledged again)