Tutorial 11, Invalid Handle / Errors
This tutorial builds on the first tutorial, so be sure to do that first!
[Tutorial 1, BlendELF Basics]
In this tutorial you will learn how to deal with errors.
Step 1: Invalid handle error
Probably the most common error that you will encounter with BlendELF is the "invalid handle" error. This happens when you are passing an invalid handle to a function. One example would be, if you are trying to load a scene with elf.LoadScene() and passed an invalid path to it, in which case the load would fail. The function would still return an handle to you, but the handle would be empty. You can check if the handle contains something with elf.IsObject(). Here is an example:
scn = elf.LoadScene("levels/level1.pak")
if elf.IsObject(scn) == false then
print("error: could not load level!")
end
Also the invalid handle error happens when you are passing an handle of the wrong type to an function. For example, you can't pass an handle of type
light to
elf.AddCameraToScene. This kind of errors are less common, but you can still check for an object type with
elf.GetObjectType(). The types are listed in the
API DOC.
Step 2: Parameter errors
Sometimes you may run into some parameter errors. A BlendELF function may report that it was expecing an
handle type argument, but it got
nil instead, or some other type. Due to the scripting bindings being automatically generated by SWIG, BlendELF doesn't yet report the line where the error happened for these kind of errors (the date when this part of the tutorial was written is Jun 23 2010, things may have changed afterwards). This is being worked on. For now you will just have to check the code yourself. Fortunately the execution of the script ends where the error has happened, so it is much easier to debug an error like this.
Thats it! I hope you enjoyed the tutorial, and if you have any comments about it, please post to the
forums.
Copyright © 2009-2010 Samuel Anjam