Time + values

Blitz3D Forums/Blitz3D Programming/Time + values

David819(Posted 2004) [#1]
ok, i have been working on a function that changes the sky from day to night and vise versa, i have made it work by user control, but i wish it to change at sertain times, i need to know how to create a clock of somesort which run but the computers time but minutes are as hours and such, how do i get it to make the value start to go up say at 7.00 and then start to go down at 19.00?


Ross C(Posted 2004) [#2]
Well, you could set a variable to the value of millisecs() then check the difference between the values.

Time = Millisecs()


Then check to see what time it is.

Current_time = Millisecs() - Time


That would return the current time in milliseconds. Just divide that number by 1000 to get it into seconds, and work from there. You'd want to set the Time value to be midnight or something, as this will make it easier to work out the current time :)


David819(Posted 2004) [#3]
ok, do you think you could edit the code below to show how to do that please, without the use of keys:

D#=0
N#=1

While Not KeyHit(1)

If KeyDown(200) Then

If D#<=0 Then D#=D#+0.01
If D#<1 And D#>0 Then D#=D#+0.01
If D#=>1 Then D#=1

If N#=>1 Then N#=N#-0.01
If N#>0 And N#<1 Then N#=N#-.01
If N#<=0 Then N#=0

EndIf

If KeyDown(208) Then

If D#=>1 Then D#=D#-0.01
If D#>0 And D#<1 Then D#=D#-.01
If D#<=0 Then D#=0

If N#<=0 Then N#=N#+0.01
If N#<1 And N#>0 Then N#=N#+0.01
If N#=>1 Then N#=1

EndIf

Cls

Text 0,0,"Day: "+D#
Text 0,20,"Night: "+N#
Flip
Wend
End


Ross C(Posted 2004) [#4]
Ok, i'll try and edit it, but i'll need to take most of it out :) I'll accelerate the time, because you don't want to be waiting 24 hours ;) Every 1000 milliseconds is an hour.

This code starts from midnight.

Graphics 640,480
Setbuffer Backbuffer()

Global Time = MilliSecs()

Global Status$

While not keyhit(1)

   Cls

   If Millisecs()- Time < 7000 then ; 7000 means 7:00 hours
      Status$="Night"
   ElseIf MilliSecs() - Time < 19000 then ; 19000 means 19:00 hours
      Status$="Day"
   Else ; the else is because it isn't day time, so it must be night time
      Status$="Night"
   End If

   If Millisecs() - Time > 24000 then ; check to see if 24 hours has past, and if so, start a new day.
      Time = Time + 24000 ; wrap the day back round to midnight again
   End if

   Text 0,0, " Day or Night:"+status$
   Text 0,10," Hour:"+((millisecs()-Time)/1000)

   Flip
Wend
End


Hope that helps :)


David819(Posted 2004) [#5]
Just editing it.


David819(Posted 2004) [#6]
ok, i got it to work just need to make a few adjustments and then it will be perfect (also once i have got some web space i will release it to the community) :) thanks