how does timing work?

Blitz3D Forums/Blitz3D Beginners Area/how does timing work?

Apollonius(Posted 2004) [#1]
I mean how can u make a timer like,

r_x = 20
r_y = 20
r_w = 10
r_h = 10
For x = 1 To 20

r_x = r_x + 20
r_y = r_y + 20
r_w = r_w + 20
r_h = r_h + 20

Rect r_x,r_y,r_w,r_h,0

After 5 seconds ...continue
Next


Rob Farley(Posted 2004) [#2]
delay 5000

of if you want to do something in that 5 seconds...

t=millisecs()
repeat
<do stuff>
until millisecs-t>=5000


Apollonius(Posted 2004) [#3]
wow this completly crashed ...lol

r_x = 20
r_y = 20
r_w = 10
r_h = 10
For x = 1 To 20

r_x = r_x + 20
r_y = r_y + 20
r_w = r_w + 20
r_h = r_h + 20

Rect r_x,r_y,r_w,r_h,0
Delay 5000 

Next



_PJ_(Posted 2004) [#4]
you have the Delay within your for/next loop, so it waits 5 seconds 20 times = 100 seconds.


Kanati(Posted 2004) [#5]
Graphics 800,600,16,2 ;set graphics mode 
r_x = 20 
r_y = 20 
r_w = 10 
r_h = 10 
SetBuffer BackBuffer() ;create a backbuffer (double buffering)
Color 255,255,255	;set foreground color to white
For x = 1 To 10

	r_x = r_x + 20 
	r_y = r_y + 20 
	r_w = r_w + 20 
	r_h = r_h + 20 

	Rect r_x,r_y,r_w,r_h,0 
	Delay 5000 
	Flip	;flip the buffers 
Next 

;Note there's no CLS command so all rects remain on screen


To see only one rectangle at a time add
[Code]Cls[/code]
right after the For command and run it again.


Apollonius(Posted 2004) [#6]
that code lags/freeze the program it does draw stuff but it tend to fk up


tonyg(Posted 2004) [#7]
Kaisuo,
You say the code posted by Kanati lags/freezes but it does exactly what you asked for in your original post.
e.g.. Rect r_x,r_y,r_w,r_h,0
After 5 seconds ...continue
Next
The DELAY 5000 will stop the entire program for 5 secs and
then continue.
You might need to explain more what it is you want to achieve.


Yan(Posted 2004) [#8]
The only reason you get a wrong answer on this forum is because you've asked the wrong question...mostly ;o)

Is this what you're after?
Type rectangle
	Field r, g, b
	Field x, y, w, h
End Type

Graphics 640, 480, 0, 2
SetBuffer BackBuffer()

r_count = 0

time = MilliSecs()

Repeat
	Cls
	
	; If times up, add a new rectangle to the list
	If (MilliSecs() - time) >= 1000
		If r_count < 20
			r.rectangle = New rectangle
			r\r = Rand(255)
			r\b = Rand(255)
			r\g = Rand(255)
			
			r\x = Rand(539)
			r\y = Rand(379)
			r\w = Rand(100)
			r\h = Rand(100)
			
			r_count = r_count + 1
			time = MilliSecs()
		EndIf
	EndIf
	
	; Draw all the rectangles in the list
	For r.rectangle = Each rectangle 
		Color r\r, r\b, r\g
		Rect r\x, r\y, r\w, r\h, 1
	Next
	
	Color 255, 255, 255
	Text 0, 0, CurrentTime$()
	
	Flip
Until KeyHit(1)

End
YAN


Kanati(Posted 2004) [#9]
You think throwing in types and such is going to clear it up for him? SIIIIMMMPLE... You forget those first few days of programming when PRINT was a stumbling block for you, Yan. :)


Yan(Posted 2004) [#10]
I started programming in machine code...so...no ;op


YAN


CS_TBL(Posted 2004) [#11]
Even some experienced coders can be a bit scared of blitz-types, let alone Kaisuo :)


Apollonius(Posted 2004) [#12]
types seems like a block of variables to me...

but yeah Yan-san the MilliSecs() command is exactly what I wanted, I wanted to make somekind of Timer, like stuff still execute itself but additional stuff executes itself after a certain time. and this actually does it in my opinion :o