Page 1 of 1

AITestMode

Posted: 07 Jun 2008 13:23
by paullb
I hope this isn't a silly question but I can't figure out how to use AITestMode.

I know I have to instante it to use AITestMode, but how do I destroy it to return back to normal mode?

Re: AITestMode

Posted: 07 Jun 2008 15:36
by TrueBrain
The end of scope does.

/* Exec Mode */
{
local test = AITestMode();
/* Test Mode */
}
/* Exec Mode */

Easy as pie :)

Re: AITestMode

Posted: 07 Jun 2008 19:08
by Finaldeath
There is a good example of it in the WrightAI. Funnily enough, yeah, you only need braces - nothing actually defining that section apart from them - for it to operate.

There will be eventually some good examples on the wiki too.

Re: [NoAI] AITestMode

Posted: 07 Jun 2008 23:28
by paullb
So basically I have to let a local variable get destroyed as it scope ends?

What if I wish to switch between normal and test mode inside a function (lets ignore for the moment if that is good practice or not) would I just have to keep on instantiating AITestMode and AIExecMode instances or is there some equivalent to

local test = AITestMode;
... do some code ...
delete(test);

Re: [NoAI] AITestMode

Posted: 07 Jun 2008 23:35
by TrueBrain
The latter works just as well. What you can also do, to make things more readable for yourself:

Code: Select all

function a() {
  {
    local test = AITestMode();
    /* Test */
  }
  {
    /* Exec */
  }
  {
    local test = AITestMode();
    /* Test */
  }
}
You can start a scope when ever you want :)

And if you want to make REALLY sure you get in ExecMode, add:

Code: Select all

    local exec = AIExecMode();
(a situation might arise where your function is called in TestMode ;))

Re: [NoAI] AITestMode

Posted: 08 Jun 2008 09:48
by Roujin
The equivalent for your example would be (if i'm not mistaken):

Code: Select all

local test = AITestMode();
// code
test = null;
because as soon as you set your variable to something else and no variable references the AITestMode anymore, it also goes out of scope.
(please confirm)
Nevertheless, for readability, why not just use blocks like TrueLight suggested?