Here's a 'Debug' function that I have been using for our Open Source RPG. It comes in really handy for large programs when you have programmed in a lot of catch-all type code to prevent annoying crashes. For example, instead of simply loading an Object into your game, you would probably want to make sure the game doesn't crash just because an object is missing. So you write some code like this:
Function Safe_Load_Object(File$,ObjectID)
If ObjectID<1 Then ObjectID=Free_Object()
If Object Exist(ObjectID)
ObjectID=Free_Object()
Endif
If File Exist(File$)=0
Exitfunction 0
Endif
Load Object File$,ObjectID
Endfunction ObjectID
Eventaully, all your code is smooth working like this little snippet, but something is going wrong in your code (maybe even on someone else's pc). How do you find it? Debug mode won't work and stepping through the 20k lines of code and 1000's of loops will send anyone to the loony bin. Well, this is where this little snippet comes in handy. It reports all the little errors that you don't want crashing your code, but might need to know about.
The Debug function opens up a text file called Debug.txt and write any error messages you want to it. I can tell you, that as I add this function into the RPG code, it is making life easier. It can either be added in as a permanent debug, or a temporary one. Here's the code:
Function Debug(text$)
if text$="" Then Exitfunction
Dim NewDebug(0)
If NewDebug(0)=0
If File Open(31)=1 Then Close File 31
If File Exist("Debug.txt")=1 Then Delete File "Debug.txt"
Open To Write 31,"Debug.txt"
Write String 31,Get Date$() + " : " + Get Time$()
NewDebug(0)=1
Endif
If File Open(31)=0
Open To Write 31,"Debug.txt"
Endif
Write String 31,text$
`Close File 31
Endfunction
And here's the little snippet from above with the Debug functionality added in.
Function Safe_Load_Object(File$,ObjectID)
If ObjectID<1 Then ObjectID=Free_Object()
If Object Exist(ObjectID)
Debug("Load Error: Safe Load ObjectID already in use; "+Str$(ObjectID)+". Trying to replace.")
ObjectID=Free_Object()
Endif
If File Exist(File$)=0
Debug("Load Error: Safe Load Object File does not exist; '"+File$+"'.")
Exitfunction 0
Endif
Load Object File$,ObjectID
Endfunction ObjectID
Open MMORPG: It's your game!