In the past we've had some occasional 'phantom bugs' (The Phantom of the Script Code (where is ALW when you need him[grin])) in scripting, but most of them could be solved by realizing a syntax error in the code. Some, however, would not go away, and last night I had finally had enough of it.
I had a script, which was totaly syntax correct, but for some reason it would do this.
OnMouseClick(){ LockPlayer(true); if(some_condition1) { if(some_condition2) { if(some_condition3) { SomeFunction(); } } }<-returns from the function here LockPlayer(false);}<-instead of here
this was very disturbing, but now, that I found somthing I could easily reproduce, I decided that this was definetly a bug (not a syntax issue).
after stepping through the ScriptProcess executor code (omg, so horrible to watch code execute code lol), I realized a fatal flaw in the Queue Next Instruction code (which was used 9 times in the executor).
The bug basically said:
1.If I am jumping out of a branch, find my next sibling instruction.
2.If I dont have a next sibling instruction, go to my parent's next sibling instruction.
and that is where the logic ends.
now this works in the case of:
if(){ if() { Func();<-instruction head } <-next sibling(nothing)}Func(); <-parent's next sibling(function)
however when you have this:
if(){ if() { if() { Func();<-instruction head } <-next sibling(nothing) } <-parent's next sibling(nothing)}Func(); <-parent's parent's next sibling(function)
it only looks backwards up to the parent's next sibling, which can potentially be nothing.
In this case, the queue next instruction code returns a null instruction, which signals the executor that we are done, so it returns before finishing the rest of the exection, in short.
NOT GOOD!
So, since this large(20 lines) block of code was duplicated 9 times in the executor, i made it into a function.
To both reduce code size and code redundancy(and thus variations(bugs) between the duplicates)
(see, post optomization is very plesant =D),
And then I modified it so that it would cascade backwards until it finds either:
1.the next sibling to execute: execute it.
2.the end of the root function: return.
This solved the problem, and now all is good in script land. =D
Hopefuly there are no others lurking about =)
Chances are there arnt, since the scripting engine has been used a lot, under many different pieces of code, so it is hard to belive another such bug exists. Then again, we were able to use the scripting engine for near on a year (albeit noticing bugs) without having and serious crash. So, who knows =D