[NoGo] Tutorial ("Beginner Tutorial" in bananas)

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

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Zuu »

Good news, among the developers, we have now found a way to simplify the task of setting up cyclic dependencies. Thus, adding an AI to the Beginner Tutorial package should be doable.

I'm not exactly sure yet how the AI should be told about the location of the industries and eg. the canal. The scenario contain signs that the GS read through the TileLabels library. The signs are removed as they are read by the TileLabels library, thus not visible for the AI. If the setting to show competitor signs is enforced to be off, then AI could get its own set of signs and a port of TileLabels, but that might be a lot of work to not hard code the coordinates into the code.

Maybe the easiest solution is that in the trigger sign(s) from GS -> AI, include the industry IDs and tile coordinates that are needed for it to build. Either by using scp or by using specific code for this task.


Edit: fixed typo
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by krinn »

as the tutorial use already a scenario, you could just make that scenario using two towns only and two industry no ?

So ai don't need to guess any path, without choice the guess is easy : use that industry to provide good to that other industry.
And this could be resume to :)
AI start
AI get number of industry (so if any new one comes, it will ignore them)
AI wait for the sign

Once GS need it :
GS put sign to AI (hehe FFS START!)
AI then just start its job, building the route from industry1 to industry2.
Not even a sign is need, put a tree at tileX in the scenario, AI wait for tree disappears and GS just need to clear tileX.

Also you could use the TileLabel functions in the AI like it is right now, and build sign as AI owner.
And make a modified TileLabel for GS that don't remove sign itself. Switch to ai company and read signs, but don't remove them.
You'll endup with AI and GS both have read the signs, only the AI remove them, but still both will knows where they were at first.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Zuu »

While the scenario means that certain things will be hardcoded, I used the sign way of hardcoding locations instead of having coordinates written in .nut files. With signs, you see the signs in the scenario editor when updating the scenario which makes it easier to handle than having coordinates scattered all over the .nut files.

What I think now is that the GS will place these signs with AI company as owner:

Code: Select all

$I:1|2|3
$C:4|5|6|7

1 = refinery industry id
2 = industry id of oil rig 1 (the near oil rig)
3 = industry id of oil rig 2 (the far oil rig)
4 = tile index of canal start tile
5 = tile index of canal end tile
6 = lock tile 1
7 = lock tile 2
To trigger the AI this sign could be used:

Code: Select all

$Start
When the AI is done it create:

Code: Select all

$Done

All signs are preferable put at tile 0,0. The receiving part should remove the sign as soon as it sees it. Then the only users that will likely see it are those that have read the forum and are aware of the existence of it.

To de-code the signs SuperLib.Helper.SplitString(delimiter, string, limit = null) may be useful.



EDIT: It may be better that the tile label location signs are not created until just before the $Start sign is created. That way the AI should first wait for $Start and only after that is found, it should look for the other two signs and read + remove them.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by krinn »

i think you shoud put them fast. It won't change a thing, AI will still wait for the START key.
but while waiting the START, AI can still do useful thing with those info (pathfinding route while waiting START).
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Zuu »

Ok, I've added code to the GS and created an AI that will wait for the trigger and then respond with $Done. I haven't yet added this AI into the scenario, so if you try this out, you need to start the AI via the console "startai TutorialShipAI" before you get to the dialog where it ask you if it should use an AI to build the ship route.

To help testers to avoid version conflict with current tutorial version 9, I've made this the version 10 of the tutorial, but will not upload it to bananas until things have settled and the code that actually builds the ship route have been integrated to the AI. Next bananas version will probably be version 11.
Attachments
Tutorial-v10.tar
Tutorial Game Script
(130 KiB) Downloaded 214 times
Beginner Tutorial.scn
To use with version 10 of the Tutorial GS
(41.04 KiB) Downloaded 235 times
TutorialShipAI-v10.tar
Warning: this AI is only visible if gui.ai_developer_tools is on.
Start it with "startai TutorialShipAI" from the console.
(10 KiB) Downloaded 224 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Zuu »

krinn wrote:i think you shoud put them fast. It won't change a thing, AI will still wait for the START key.
but while waiting the START, AI can still do useful thing with those info (pathfinding route while waiting START).
In this case there isn't much to path find. The canal start/end is given by the GS. Even the exact tiles to place the locks are given. The hardest part is probably to figure out where to place the dock and ship depot.

For now I've used the method where the AI is idle until it sees $Start because, in many situations the user will not even use the option to complete the ship chapter. In that case we don't want to slow down his/her computer by ship path finding for no good reason. Additionally, the current solution is a bit easier as the GS <-> AI communication can be limited to fewer places in the code.

But indeed, you have a point with pre-caching computations. I just don't see that it is worth the effort in this case.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by MinchinWeb »

Wow, a lot can happen in one night. I will look into the provided AI and see if I can build it around that. It sounds like it should work. Thanks!
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by MinchinWeb »

My AI runs! It probably has a couple of rough corners, but it does the job. Zuu, can you hook the AI up with some extra money?

FYI (for future reference), when you read data from a sign, it stores it as a string. If you want to use it as a TileID or IndustryID, if first needs to be converted to an integer. This had be cause some extra confusion at the start for me...

What it does:
  • Builds a ship to transport oil from the both of the oil rigs to the oil refinery. Will build docks, depots, and buoys as required.
  • Build canals
  • Takes about a month to complete
What is doesn't do:
  • Build more than one ship (per route), replace old ships, or otherwise manage ships
  • Terraform
Attachments
TutorialShipAI-v10-WM.tar
Working Tutorial AI by MinchinWeb
(30 KiB) Downloaded 212 times
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
BlueDeath
Engineer
Engineer
Posts: 53
Joined: 24 Jan 2010 22:16

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by BlueDeath »

hm, soon I'll test the tutorial after making some suggestions, playing might be good as well ;-)
User avatar
Ben1338
Traffic Manager
Traffic Manager
Posts: 171
Joined: 17 Nov 2007 17:23
Skype: ben313371

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Ben1338 »

Hey there, I found Version 9 of the tutorial to be extremily tempourmental with me (I maneged to loose my way twice and I do not know when I have broke it or what to do).

So, I've been thinking of suggestions of which could improve the flexibility of it.

Also with the senareo, might I suggest adding oil wells near the oil refinery so that you can complete the scenareo without using the shipping chapter and instead, create an alternate chapter 4 which would cover the lorries using the oil wells isntead of the oil rig.

So like, chapter 4b could be using the wells, accessed directly from the chapter selection, chapter 4a could be accessed via the shipping chapter.

Also, I think that the chapter selection screen could be improved too. For example:
Have a list of included chapters formated like a table, so for example:
Have scenareos listed in one column (formatted with clickable buttons) and have the description of them in another column. Suitable titles must be included. Note chapter 4a and 4b could be formatted as 4 for simplicity and only 4b would be displayed in the chapter selection box.

An example of the table of the Tutorial V9 chapter selection is in the attachments.

I guess for me getting lost, I would also advise having a little window saying what you're suppost to be doing in case that the person forgets to do what he's suppost to be doing. Something that is small and does not consume a lot of screen space and something which canot be closed.

I'd say that it's good, but I think that there's a lot to be improved about it.

It would also be good to include the description of what the buttons do similar to the old tutorial in TTD.

I guess what the old tutorial in the origonal TTD and TT did, was that it fully employed AI and took over your mouse and did stuff for you (back then, the right mouse button enabled the tool description, a description of what the button does and why it's there, and it made simple services using your mouse to create them. There was absolutely no way to deviate away from the tutorial. I on the other hand, deviated from the tutorial quite a lot which caused the attitude and when the problems occured.

Thank you for reading my post. I sorta stumbled accross the "tutoral" senareo while rummaging through the online content in OTTD and thought I'd give it a shot in a hope that I could learn something from it.

I certainally hope my post helped.

These are only suggesstions, take them if you feel like they're worth implementing.
Attachments
Tutorial table example.xls
An example of the table version of the chapter selection. So you could format it as a table in a single window rather than having "previous", "next" and "select" buttons that transfer you to other windows.

I think it would make it more intuitive.

This file requires either Microsoft Office or Open Office.
(8 KiB) Downloaded 227 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Zuu »

Ben1338 wrote:Also with the senareo, might I suggest adding oil wells near the oil refinery so that you can complete the scenareo without using the shipping chapter and instead, create an alternate chapter 4 which would cover the lorries using the oil wells isntead of the oil rig.

So like, chapter 4b could be using the wells, accessed directly from the chapter selection, chapter 4a could be accessed via the shipping chapter.
Its a known and unwanted limitation that you must complete the ship chapter before you can do the lorry chapter. The solution that we have come up with is an AI that MinchinWeb have kindly contributed which will complete the ship chapter for you. This AI is not yet included in the bananas version as I haven't had motivation and time yet to do the required work to include it. It may sound silly, but with possible 10 different OpenTTD related projects each of them have small things that could be done.

Ben1338 wrote:Also, I think that the chapter selection screen could be improved too. For example:
Have a list of included chapters formated like a table, so for example:
Have scenareos listed in one column (formatted with clickable buttons) and have the description of them in another column. Suitable titles must be included. Note chapter 4a and 4b could be formatted as 4 for simplicity and only 4b would be displayed in the chapter selection box.

An example of the table of the Tutorial V9 chapter selection is in the attachments.
The reason why several GUI things are as they are now, is that the flexibility of what a Game Script can do gui-wise is not very large. GS can create query-windows with up to 3 buttons. I've already sort of abused them to create a wizard-style of dialog. If you move the dialog you'll notice that it moves back to the centre of your screen when you click on a button. That is because when you click on a button, the window is closed and then a new query-window is opened.

I don't want to say that it is impossible to improve it, just that to do so, there need to be changes in OpenTTD to provide facilities for GS to do more advanced GUI stuff. Something that I'm quite sure will be accepted if someone implements it well, its more on the problem that someone have to make it. Until then my ambition to do what is possible within the current framework.
Ben1338 wrote:I guess for me getting lost, I would also advise having a little window saying what you're suppost to be doing in case that the person forgets to do what he's suppost to be doing. Something that is small and does not consume a lot of screen space and something which canot be closed.
Most tasks (but unfortunately not all) have a reminder window that appears after about 30 seconds or so if I remember the timing correctly.

Still there are plenty of ways to shoot yourself in the foot in the tutorial. That is true. One such way is to use hotkeys, which isn't exactly that easy to solve in all cases. In most cases the tutorial is coded to wait for a certain window to open rather than for you to click on a highlighted button. This solves some of the hotkey-shoot-yourself-in-the-foot issues, but some aren't possible to solve this way.
Ben1338 wrote:I'd say that it's good, but I think that there's a lot to be improved about it.
I certainly agree that there are lot of things that could get improved. While I did point out some limitations in the current GS API, there are several things that could be improved in the the Tutorial also today. And the API is neither something that is impossible to change. Quite the opposite I would say. It's still a young API which gives a good base that could be built on with further improvements.

Ben1338 wrote:I certainally hope my post helped.
Thank you for taking your time to provide feedback. Getting user feedback is always valuable to better know which parts that are confusing for users who haven't programmed the tutorial themself. :wink:
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Ben1338
Traffic Manager
Traffic Manager
Posts: 171
Joined: 17 Nov 2007 17:23
Skype: ben313371

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Ben1338 »

Alright, that pretty much clears up everything that I ahve said and I understand the limitations and greatly appretiate the time that you took to writing back to me.

Thank you for the very fast reply.
BlueDeath
Engineer
Engineer
Posts: 53
Joined: 24 Jan 2010 22:16

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by BlueDeath »

hmm, I am just thinking about your chapter selection.

When you finish I would change the text to:

"Continue with next chaper or select an chapter on your own?"
"Select chapter" "continue"

for selecting a chapter:
"previous" "start" "next"
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Zuu »

Note that the buttons must be up to three from this set of predefined buttons:
http://nogo.openttd.org/api/1.2.3/class ... 21d9594ec7

If you still using this set of buttons find improvements, please post them.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
BlueDeath
Engineer
Engineer
Posts: 53
Joined: 24 Jan 2010 22:16

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by BlueDeath »

Ah, I see it's getting tricky.

The first time I intuitivly clicked on "yes" and got the introduction a second time...
Well you can argue that you should read the question to be answered, but useing "continue" instead of yes/no is possibly more convienent. This on the other hand forces to abuse some other button.

What do you think about "accept" or "yes" (on the left side) to select an chapter and "continue" (on the right) for the next chapter?

??
You can choose an chapter yourself hitting >button< or just continue with the next chapter. What do you wish to do?
??
Do you accept on selecting a chapter on your own or just wish to continue in order?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Zuu »

Update - Version 11

I have finally found some time to add MinchinWebs Ship AI to the tutorial and upload update which contains this nice addition.

Changelog:
  • Add: Ship AI (TutorialShipAI-v10-WM.tar) by MinchinWeb
  • Fix (Ship AI): various bugs in the GS -> AI conversion and adaptation of Operation Hibernia to work in the tutorial context.
    • GSMap -> AIMap
    • GSMarine -> AIMarine
    • Industry ID of refinery was used where a tile was expected
    • Push canal building back to after the first connection, to get a behaviour more close to the instructions for humans.
    • Don't allow to reject any of the hard-coded industries
    • Don't reject the only oil ship available due to unwanted capacity
  • Change (Ship AI): Extend SuperLib.Log to use the same log level AI setting as MetaLib and change info.nut of AI to use the debug level setting name that MetaLib uses. (not really relevant for any user, but if anyone wants to know how to merge SuperLib and MetaLib log systems to only have one setting for the log level, you can look into the Beginner Tutorial Ship AI ;-) )
  • Change: The dialog shown at the end of a chapter have been tweaked based on feedback by BlueDeath.

All three parts have been uploaded to Bananas and should already been linked together in a cyclic dependency.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
fernando83
Engineer
Engineer
Posts: 3
Joined: 06 Mar 2013 11:29

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by fernando83 »

Thank you guys for this great tutorial!

I wonder how can I translate this tutorial to another language?

when i edit the language file(to chinese) and run the tutorial, the error message pop up just like this
Attachments
Unnamed%2C 30th Jan 1950.png
Unnamed%2C 30th Jan 1950.png (30.21 KiB) Viewed 10881 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by Zuu »

Make sure that the language file remains in UTF8. If the encoding is changed, this error can occur. Though I don't know if there are any other options than UTF8 for Chinese which your editor may have selected or if UTF8 is already defacto standard for Chinese. (In Europe, there have been other older encodings that some bad editor like to use instead of UTF8 unless you force the editor to use UTF8)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
fernando83
Engineer
Engineer
Posts: 3
Joined: 06 Mar 2013 11:29

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by fernando83 »

Zuu wrote:Make sure that the language file remains in UTF8. If the encoding is changed, this error can occur. Though I don't know if there are any other options than UTF8 for Chinese which your editor may have selected or if UTF8 is already defacto standard for Chinese. (In Europe, there have been other older encodings that some bad editor like to use instead of UTF8 unless you force the editor to use UTF8)
I use windows notepad to edit the language file. and i also tried to save the file in utf-8 format. but this error still remains.

should i use a more advanced editor?
fernando83
Engineer
Engineer
Posts: 3
Joined: 06 Mar 2013 11:29

Re: [NoGo] Tutorial ("Beginner Tutorial" in bananas)

Post by fernando83 »

Thanks Zuu,

problem solved as I download notepad++ and use it to edit the file!
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 4 guests