Error Trapping
Blitz3D Forums/Blitz3D Beginners Area/Error Trapping
| ||
Does anyone know of some good techniques for "error trapping"? Sometimes I have problems with collisions and recently it has been brought to my attention that I should put some of the stuff in my code. |
| ||
For a start:x = LoadMesh("model.x") If Not x RuntimeError "File missing" EndIf |
| ||
I will have to study that one. |
| ||
It's really simple: Hope that helped =) |
| ||
To expand on that, when ever you load an entity, sound or image or most external media, it returns an integer number, i suppose it would be a memory location of the stored media. Any number really, except zero, would mean a successful load. So, therefore by checking for zero, your determining if it was loaded. |
| ||
it returns an integer number, i suppose it would be a memory location of the stored media. The handle to the _____ is a memory address to the _____. |
| ||
Ok. Sometimes I've noted that it says "Entity Does Not Exist" and points to the line where the handle is first called, when it is actually failing to load the file itself. I'm not quite sure how this RuntimeError command will help much (except for customization). Anything else I should know? |
| ||
Sometimes when it says "Entity Does Not Exist", it usually means that you didn't make the loaded entity "Global". Which is highly recomended that you do. |
| ||
Yah, I'm starting to do that more. |
| ||
cool-beans |
| ||
You could intercept the error by supplying some alternative media:x = LoadMesh("model.x") If Not x x = CreateCube() EndIf However, that still doesn't catch all errors. If a surface contains too much vertices, you'll get a memory access violation, which I believe can't be trapped. I think a good way of handling errors is to place every routine that could generate an error in a Function. You can then apply the error checking inside the function. Ie: Function MyMoveEntity(ent, x#, y#, z#, global=0) if (ent <> 0) then MoveEntity ent, x, y, z, global End Function |
| ||
Good idea Warner, but that would take a while......unless you just include all of those custom functions in an 'include' file. Then just re-use them. |