The first red line gives you all the info you can get: the error occurred in RoadPathFind.nut, on line 5, character 9Ar4er wrote:
Problem WITH!!!!! Ai
Moderator: OpenTTD Developers
Re: Problem WITH!!!!! Ai
the error message provides you with valuable debugging information:
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: Problem WITH!!!!! Ai
As it seems you are a really inexperienced programmer, three things you should know (there are more but these are really important for you at the moment):
1- Think about your code: what do I want the code to do, how can I achieve this (in a general way), then think about programming language specific approaches.
2- Write code: get familiar with a language and it's properties.
3- Debug: learn what debugging is and how to approach errors and their causes.
These three are very general but apply to all languages. An example for you concerning squirrel, you want to construct a route between two cities.
1) Think about your code. You need to find cities to construct routes in between. You need to construct the route (roads, depots, stations, cars). Now we know this, think about the cities in more detail, how do you find cities (based on which properties do you want te select cities etc.). If that problem is tackeled, you need to know how to construct a route, build depots and stations, where do you want to place those, what is your approach when connecting the two towns with roads etc.
2) Write code. You now know your general approach to the construction of the route, now you need to put your thoughts in squirrel language. An example is:3) Debug. Obviously you are going to get errors, now you need to know how to find and fix those errors. Find line numbers, find error descriptions and try to understand them.
1- Think about your code: what do I want the code to do, how can I achieve this (in a general way), then think about programming language specific approaches.
2- Write code: get familiar with a language and it's properties.
3- Debug: learn what debugging is and how to approach errors and their causes.
These three are very general but apply to all languages. An example for you concerning squirrel, you want to construct a route between two cities.
1) Think about your code. You need to find cities to construct routes in between. You need to construct the route (roads, depots, stations, cars). Now we know this, think about the cities in more detail, how do you find cities (based on which properties do you want te select cities etc.). If that problem is tackeled, you need to know how to construct a route, build depots and stations, where do you want to place those, what is your approach when connecting the two towns with roads etc.
2) Write code. You now know your general approach to the construction of the route, now you need to put your thoughts in squirrel language. An example is:
Code: Select all
- get a list of towns
- sort the list of towns descending
- get the first two towns
- construct a road between the two towns
- build a station in both towns
- build a depot in both towns
- build trucks
- give orders to the trucks
- start the trucks
Re: Problem WITH!!!!! Ai
But i can't find a error becouse non pop ups on me
Re: Problem WITH!!!!! Ai
in that case there isn't an error
to see ai debug output go to far right button on menu bar and select ai debug
to see ai debug output go to far right button on menu bar and select ai debug
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: Problem WITH!!!!! Ai
i know that
i get only this
i get only this
- Attachments
-
- Capture.PNG (4.95 KiB) Viewed 2615 times
Re: Problem WITH!!!!! Ai
Ok, now add:
to the beginning of each function. Then post the debug screen
Code: Select all
AILog.Info("*function-name*");
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: Problem WITH!!!!! Ai
Have you read bullet three: "You are going to get errors.". Ergo: know what your code should do, and if something doesn't go as expected, learn how to find what goes wrong. An error is not only an error when you get notified. You really have to be more specific and have to put in more effort yourself because people are going to ignore you if you don't google yourself.Ar4er wrote:But i can't find a error becouse non pop ups on me
Re: Problem WITH!!!!! Ai
Nothing's there
Can you download this file and look for your self
Can you download this file and look for your self
- Attachments
-
- AcelaExpress.rar
- (6.83 KiB) Downloaded 57 times
Last edited by Ar4er on 22 Aug 2010 16:16, edited 1 time in total.
-
- Engineer
- Posts: 23
- Joined: 02 Dec 2009 17:06
Re: Problem WITH!!!!! Ai
Ar4er wrote:But why my Ai isn't building anything i quess problem is in hereCode: Select all
function AcelaExpress::Start() { AILog.Info("AcelaExpress Started."); SetCompanyName(); //Keep running. If Start() exits, the AI dies. while (true) <----------- here is the problem. while (true) stay here so he will always stay u forgot the brackets { <------ opening bracket this.Sleep(1); Debugs.Warning("Main loop started"); <-------- this line will also give an error Manager.ManageLoan(); // Debugs.Debug("manageOnly = " + RoadPathFind.manageOnly); if(RoadPathFind.manageOnly == false) { local vehList = AIVehicleList(); vehList.Valuate(AIVehicle.GetVehicleType); vehList.KeepValue(AIVehicle.VT_ROAD); local numOfVehs = vehList.Count(); if(AIGameSettings.GetValue("vehicle.max_roadveh") <= numOfVehs) { Debugs.Info("Max amount of road vehicles reached"); RoadPathFind.manageOnly = true; } else { RoadPathFind.Main(); } } else { Debugs.Info("Sleeping because there is nothing to build"); this.Sleep(25); } } } <------ close bracket function AcelaExpress::Stop()
Re: Problem WITH!!!!! Ai
Radicalimero wrote:Ar4er wrote:But why my Ai isn't building anything i quess problem is in hereCode: Select all
function AcelaExpress::Start() { AILog.Info("AcelaExpress Started."); SetCompanyName(); this is 19 //Keep running. If Start() exits, the AI dies. this is 20 while (true) } <----------- here is the problem. while (true) stay here so he will always stay u forgot the brackets { <------ opening bracket this.Sleep(1); Debugs.Warning("Main loop started"); <-------- this line will also give an error Manager.ManageLoan(); // Debugs.Debug("manageOnly = " + RoadPathFind.manageOnly); if(RoadPathFind.manageOnly == false) { local vehList = AIVehicleList(); vehList.Valuate(AIVehicle.GetVehicleType); vehList.KeepValue(AIVehicle.VT_ROAD); local numOfVehs = vehList.Count(); if(AIGameSettings.GetValue("vehicle.max_roadveh") <= numOfVehs) { Debugs.Info("Max amount of road vehicles reached"); RoadPathFind.manageOnly = true; } else { RoadPathFind.Main(); } } else { Debugs.Info("Sleeping because there is nothing to build"); this.Sleep(25); } } } <------ close bracket function AcelaExpress::Stop()
error
- Attachments
-
- Capture.PNG (6.74 KiB) Viewed 2605 times
-
- Engineer
- Posts: 23
- Joined: 02 Dec 2009 17:06
Re: Problem WITH!!!!! Ai
those arrows <------
where to point out the problem the correct code should be
where to point out the problem the correct code should be
Code: Select all
function AcelaExpress::Start()
{
AILog.Info("AcelaExpress Started.");
SetCompanyName();
//Keep running. If Start() exits, the AI dies.
while (true)
{
this.Sleep(1);
AILog.Warning("Main loop started");
Manager.ManageLoan();
// Debugs.Debug("manageOnly = " + RoadPathFind.manageOnly);
if(RoadPathFind.manageOnly == false)
{
local vehList = AIVehicleList();
vehList.Valuate(AIVehicle.GetVehicleType);
vehList.KeepValue(AIVehicle.VT_ROAD);
local numOfVehs = vehList.Count();
if(AIGameSettings.GetValue("vehicle.max_roadveh") <= numOfVehs)
{
AILog.Info("Max amount of road vehicles reached");
RoadPathFind.manageOnly = true;
}
else
{
RoadPathFind.Main();
}
}
else
{
AILog.Info("Sleeping because there is nothing to build");
this.Sleep(25);
}
}
}
Re: Problem WITH!!!!! Ai
this is because AroAI uses a custom Debug system. you will have to change it before anything will workRadicalimero wrote:Code: Select all
Debugs.Warning("Main loop started"); <-------- this line will also give an error
also, you can't expect us you write your code for you. Most of us have our own AIs to write. you MUST learn what the error messages mean and how to fix them.
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: Problem WITH!!!!! Ai
it seems to work becouse that i see some working on ai debug
now i can finaly do something by my own
As for the error i think i fix those lines where is error by AILog.Info i quess that would work
now i can finaly do something by my own
As for the error i think i fix those lines where is error by AILog.Info i quess that would work
- Attachments
-
- Capture.PNG (13.18 KiB) Viewed 2600 times
Re: Problem WITH!!!!! Ai
i done it i done thank you Lord Aro, Radicalimero, And Zuu
Thank you all i am so sorry if i was big pain thank you guys best forum ever now i am going to try add function so he makes 3 town route
Thank you all i am so sorry if i was big pain thank you guys best forum ever now i am going to try add function so he makes 3 town route
Re: Problem WITH!!!!! Ai
well done!
don't forget to credit me!
it took me months to get that code right...

don't forget to credit me!
it took me months to get that code right...

AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: Problem WITH!!!!! Ai
don't worry i am not selfwish
and i would buy you a cake if you lived next to me
and i would buy you a cake if you lived next to me
Re: Problem WITH!!!!! Ai
One more question how to make my ai so he do random events like one time he is building buses but another time trucks
Re: Problem WITH!!!!! Ai
I would do something similar to the company name picker. You would have to write a lot of code so the AI can support trucks though.
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: Problem WITH!!!!! Ai
i was think about that too but i didn't find this way of coding in any AI
Re: Problem WITH!!!!! Ai
There is a bunch of random functions in AIBase: http://noai.openttd.org/docs/1.0.3/classAIBase.html
For example if you want to use trucks in 64% of the cases, do this:
AIBase::RandItem() is useful if you want to arrange items in a list in a random order. I use this in the industry/town selection alghorithm in SimpleAI. (see cBuilder::FindService() in builder.nut)
Example of this:
SimpleAI uses a lot of random functions here and there, the only problem is that my code is not very well commented, so it is not the easiest to understand 
For example if you want to use trucks in 64% of the cases, do this:
Code: Select all
if (AIBase.Chance(64, 100)) {
// build trucks
...
} else {
// build buses
...
}
Example of this:
Code: Select all
local townlist = AITownList();
townlist.Valuate(AIBase.RandItem); // after valuating the items are arranged in a random order
local town = townlist.Begin(); // pick a random town

Who is online
Users browsing this forum: No registered users and 9 guests