Code archives/Miscellaneous/Text print queue

This code has been declared by its author to be Public Domain code.

Download source code

Text print queue by BlitzSupport2002
This is hard to describe, but it's for messages you want to display only briefly on-screen, in a queue, like the sort of messages that appear in network games, etc, then disappear.

Simply paste the stuff below into your code, add UpdatePrintQ () to your main loop, just before 'Flip', then instead of calling Print when something happens (eg. Print "Player joined"), use PrintToQ "Player joined"...

This is only for brief 'event' messages -- you can change the default timeout of messages by adding a milliseconds value to UpdatePrintQ.
Type PrintQ
	Field message$
	Field time
End Type

Function PrintToQ (message$)
	p.PrintQ = New PrintQ
	p\message = message$
	p\time = MilliSecs ()
End Function

Function UpdatePrintQ (timeout = 2000)
	Locate 0, 0
	For p.PrintQ = Each PrintQ
		Print p\message$
		If p\time < MilliSecs () - timeout Then Delete p
	Next
End Function

Comments

Mikorians2014
Fixes rapid dissapearance if lots of messages come
through simultaneously, also has a cheap midnight fix.

; ID: 481
; Author: BlitzSupport
; Date: 2002-11-09 11:07:57
; Title: Text print queue
; Description: Handles display of console-like text messages

Type PrintQ
	Field message$
	Field time
End Type

Graphics3D 640,480,32,0
a=CreateCube()
b=CreateCamera()

For t=0 To 9
PrintToQ "Hello"+Str$(t)
Next

While Not KeyHit(1)
UpdateWorld
RenderWorld
UpdatePrintQ
Flip
Wend
End

Function PrintToQ (message$)
	q.PrintQ = Last PrintQ
	p.PrintQ = New PrintQ
	If q<>Null Then f=(Abs(MilliSecs()-q\time)+2000)
	p\message = message$
	p\time = MilliSecs ()+f
End Function

Function UpdatePrintQ (timeout = 2000)
	Locate 0, 0
	For p.PrintQ = Each PrintQ
		Print p\message$
		If MilliSecs()-p\time > timeout Or MilliSecs()<1000000 Then Delete p
	Next
End Function



Code Archives Forum