AI:SQ pitfalls
From OpenTTD
Development
AI Programming
- API Documentation
- Introduction
- info.nut file
- Basics
- Using the pathfinder
- Saving / Loading data
- Things you need to know
- Squirrel
- Home page
- Common mistakes
- Lists
- Coping with OTTD errors
- Trams
- AI Libraries
AIs
[edit] require()
To include files inside your main.nut, you can use require(). This function works relative from the current file, so it should be easy to use. But, there are several things you have to keep in mind:
- It always includes the file in the global space. It isn't a code-include. So the file included has to be full code (rarely people will notice this, but it is important to know :))
[edit] Classes
Make sure you initialize all your non-static class variables in the constructor. Just giving them a value when you declare them is not enough if you create multiple instances!! If you fail to initialize a variable in the constructor it might end up with a weird value, such as copying the value from another instance of the class. The box below shows a correct way to initialize variables. The important thing is that all variables get a value in the constructor.
class Developer
{
name = null;
age = null;
constructor() {
name = "Unknown Developer";
age = 25;
}
function SetName(name);
// ...
}

