Important change to call/acall/pcall (2 juni 2009)

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
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Important change to call/acall/pcall (2 juni 2009)

Post by Yexo »

Because I assume not everyone reads the changelog:

(svn r16502) -Fix [FS#2935]: when an AI was suspended while in a function called (indirectly) via call/acall/pcall OpenTTD crashed. Fix this by disallowing AIs to be suspended while called via call/acall/pcall.
IMPORTANT FOR AI WRITERS: AIs can no longer call any DoCommand functions (change anything, build vehicles, etc.) in a function called (indirectly) via call/acall/pcall. Where possible, please rewrite your code so it doesn't use call/acall/pcall.

This change will also be in 0.7.1-RC3 and later. Please test your AIs using the latest nightly / 0.7.1-RC3 when it comes out and report all crashes. Thanks to fanioz for reporting this problem.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Important change to call/acall/pcall (2 juni 2009)

Post by fanioz »

I remembered sometimes ago there are thread about un-ability of AIList.Valuate() function to call DoCommand, and there is replacement that is made using ".call/.acall/.pcall" methode. Now, these methods is no longer could call a DoCommand :( and we only can use a normal function with a little trick as shown by yexo.

Code: Select all

 this = your_this;
==================
Forget it,
However, the program stability should be on the first place. :wink:
Thanks to yexo for fixing :D (and Rubidium - who make me confident to report the bug :lol: )
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Important change to call/acall/pcall (2 juni 2009)

Post by Zuu »

Hmm, so then placing debug signs in valuators will not work anymore. And I see my PAXLink have become pretty broken due to this. Not sure how much to change though. But I think there is at least one DoCommand that is not a debug call in it.

Thanks for the notice though.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Important change to call/acall/pcall (2 juni 2009)

Post by Bilbo »

Zuu wrote:Hmm, so then placing debug signs in valuators will not work anymore.
Well, you can place debug signs into some array and then put contents of the array on the map once the valuator is finished
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Important change to call/acall/pcall (2 juni 2009)

Post by Yexo »

Zuu wrote:Hmm, so then placing debug signs in valuators will not work anymore.
You can write a valuate replacement in squirrel without using call. I've attached the version I use in AdmiralAI.

Edit: now I have (.nut files are not allowed as attachment)
Attachments
valuator.txt
(3.43 KiB) Downloaded 160 times
Last edited by Yexo on 15 Jun 2009 13:09, edited 2 times in total.
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Important change to call/acall/pcall (2 juni 2009)

Post by Roujin »

Yexo wrote:I've attached the version I use in AdmiralAI.
No, you haven't.
* @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
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Important change to call/acall/pcall (2 juni 2009)

Post by fanioz »

Found ...in : Admiral21.tar/utils/valuator.nut :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Important change to call/acall/pcall (2 juni 2009)

Post by Dustin »

I noticed that the current release disallows commands even in test mode. That seems reasonable since it might be hard to know the difference in a callback. It would be nice to allow valuators to try operations in test mode, though. Unless of course this would also cause a crash...
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Important change to call/acall/pcall (2 juni 2009)

Post by Yexo »

Dustin wrote:I noticed that the current release disallows commands even in test mode. That seems reasonable since it might be hard to know the difference in a callback. It would be nice to allow valuators to try operations in test mode, though. Unless of course this would also cause a crash...
Maybe not a crash, but it does give problems with suspending the AI. Since there are working replacements for call/acall/List::aluate written in squirrel I see no need to enable it.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 38 guests