I believe 100% of the people here use print statement on screen and/or file to debug their Basic games.
I've came up with a module that allows you to show the logs on screen, keeping only the 10 most recent messages, add timestamp to the message and optionally save to a log file.
See the comments at the beginning to know what global variables you have to create on your main.agc file.
Here is the log.agc file:
RemStart
**********************************************************
Log Manager - by Paulo Garcia
Besides adding this module to your project, declare
the following glogal variables in your main.agc
#constant MAX_LOGS = 10
Dim logs[MAX_LOGS] as String
Dim textLog[MAX_LOGS]
Global log_idx = 0
Global fontLog = 0
**********************************************************
RemEnd
// Constants
#constant INITIAL_Y = 700
#constant FONT_SIZE = 16
#constant FONT_ALPHA = 150
#constant LOG_FILENAME = "log.txt"
// optional features - set 0 to disable, 1 to enable
#constant LOG_FILE = 1
#constant ADD_TIMER = 1
// -----------------------------------------------------------
// Initialize Text objects
// -----------------------------------------------------------
Function InitLogs()
log_idx = 0
y = INITIAL_Y
logFont = LoadImage("img/logfont.png")
For i = 0 to MAX_LOGS - 1
logs[i] = ""
textLog[i] = CreateText("")
SetTextColor(textLog[i], 255, 0, 0, FONT_ALPHA)
SetTextFontImage(textLog[i], logFont)
SetTextVisible(textLog[i], 1)
SetTextPosition(textLog[i], 0, y)
SetTextSize(textLog[i], FONT_SIZE)
SetTextSpacing(textLog[i], -5)
y = y + FONT_SIZE
Next i
If LOG_FILE = 1
// Create log file
lf = OpenToWrite(LOG_FILENAME, 0)
WriteLine(lf, "------------------------------ START -------------------------------------")
CloseFile(lf)
EndIf
EndFunction
// -----------------------------------------------------------
// Show log messages - call from update or render
// -----------------------------------------------------------
Function ShowLogs()
rem Print logs
For i = 0 to MAX_LOGS - 1
SetTextString(textLog[i], logs[i])
Next i
EndFunction
// -----------------------------------------------------------
// Add log message - call whereever is needed to log something
// -----------------------------------------------------------
Function Log(log_string as String)
If ADD_TIMER = 1
log_string = "<" + Str(Timer())+ "> " + log_string
EndIf
If LOG_FILE = 1
// Create log file
lf = OpenToWrite(LOG_FILENAME, 1)
WriteLine(lf, log_string)
CloseFile(lf)
EndIf
logs[log_idx] = log_string
log_idx = log_idx + 1
if log_idx >= MAX_LOGS
ShiftArray()
EndIf
EndFunction
// -----------------------------------------------------------
// Shift array - older message will be lost
// -----------------------------------------------------------
Function ShiftArray()
For x = 0 to MAX_LOGS -2
logs[x] = logs[x+1]
Next x
log_idx = MAX_LOGS - 1
logs[log_idx] = ""
EndFunction
I hope it will be useful to someone else. Suggestions to improve it is also welcome.
This image shows how the messages are displayed.
(*) I'd forgotten the font file I used. Now it is attached here...
Cheers
Paulo Garcia
----------
Paulo
http://www.mobilecreators.com