AITestMode

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
paullb
Traffic Manager
Traffic Manager
Posts: 129
Joined: 19 May 2008 13:11

AITestMode

Post 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?
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: AITestMode

Post by TrueBrain »

The end of scope does.

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

Easy as pie :)
The only thing necessary for the triumph of evil is for good men to do nothing.
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: AITestMode

Post 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.
Finaldeath
User avatar
paullb
Traffic Manager
Traffic Manager
Posts: 129
Joined: 19 May 2008 13:11

Re: [NoAI] AITestMode

Post 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);
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: [NoAI] AITestMode

Post 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 ;))
The only thing necessary for the triumph of evil is for good men to do nothing.
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: [NoAI] AITestMode

Post 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?
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 38 guests