I have a "generic" errorhandler function which currently just reports any error (via a huge switch for the code enums) with some details. Later on I plan to use this to also do some runtime errorhandling with it(raise funds, demolish, landscape, etc). It is a member of my main class like so:
Code: Select all
/*
* Generic error handler which displays the latest error in log and breaks for debug.
* @param error Call AIError.GetLastError() and pass the variable in as parameter.
*/
function RadAI::ErrorHandler(error) {
I have had a number of issues calling this function from within other class methods and such, an older one which I shrugged of at the time:
In my RoadBuilder class, after a number of if...else possible Do commands where returning true I have "success = true", then after:
Code: Select all
if(!success) {
local last_error = AIError.GetLastError();
::main.ErrorHandler(last_error);
...
Code: Select all
if(!success) {
::main.ErrorHandler(AIError.GetLastError());
...

More recently, and I think is the same issue (this is a segment of a landscaping function, to flatten a square of tiles corner by corner):
Code: Select all
while((corner_height = AITile.GetCornerHeight(tile, corner)) != preferred_height) {
// Raise if lower.
if(corner_height < preferred_height) {
if(!AITile.RaiseTile(tile, slope_array[index]))
// Error handler.
::main.ErrorHandler(AIError.GetLastError());
else
landscape_success = true;
}
// Lower if higher.
else if(corner_height > preferred_height) {
if(!AITile.LowerTile(tile, slope_array[index]))
// Error handler.
::main.ErrorHandler(AIError.GetLastError());
else
landscape_success = true;
}
// Check for success.
if(!landscape_success) {
Log.Warning(" - Landscapeing failed.", Log.DETAIL);
//Debug
Sign.BuildDebugSign(tile, "landscape fail: " + preferred_height);
return false;
}
}
Code: Select all
while((corner_height = AITile.GetCornerHeight(tile, corner)) != preferred_height) {
// Raise if lower.
if(corner_height < preferred_height) {
landscape_success = AITile.RaiseTile(tile, slope_array[index]);
}
// Lower if higher.
else if(corner_height > preferred_height) {
landscape_success = AITile.LowerTile(tile, slope_array[index]);
}
// Check for success.
if(!landscape_success) {
Log.Warning(" - Landscapeing failed.", Log.DETAIL);
//Debug
Sign.BuildDebugSign(tile, "landscape fail: " + preferred_height);
// Error handler.
::main.ErrorHandler(AIError.GetLastError());
return false;
}
}
In both of the above examples AIExecMode is active, which I thought may be the cause. The issue seems to lie with scope...
So am I doing something wrong?