File I/O in Squirrel

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
griffin71
Traffic Manager
Traffic Manager
Posts: 142
Joined: 31 Mar 2007 13:11
Location: Amsterdam

File I/O in Squirrel

Post by griffin71 »

A simple question: is there any way to output information to a file in Squirrel?

I'd like to write the contents of an array to a file. Printing everything to the AI Debug screen is a pain, as it's too much information, and you can't copy characters from the Debug in addition.

Is there somthing like fopen(), fclose, fprint?
A game worth playing is a game worth modding :-)
griffin71
Traffic Manager
Traffic Manager
Posts: 142
Joined: 31 Mar 2007 13:11
Location: Amsterdam

Re: File I/O in Squirrel

Post by griffin71 »

Hm, I'm sorry about asking this.

You can do file I/O, check out here.
A game worth playing is a game worth modding :-)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: File I/O in Squirrel

Post by Yexo »

griffin71 wrote:Hm, I'm sorry about asking this.

You can do file I/O, check out here.
That part of the squirrel libraries are not supported by OpenTTD. If you really need this, you'll have to compile OpenTTD yourself after enabling those functions.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: File I/O in Squirrel

Post by krinn »

start openttd with -d ai=5
and you'll get the log in your console
griffin71
Traffic Manager
Traffic Manager
Posts: 142
Joined: 31 Mar 2007 13:11
Location: Amsterdam

Re: File I/O in Squirrel

Post by griffin71 »

krinn wrote:start openttd with -d ai=5
and you'll get the log in your console
Thanks! But how dow I copy from the console?

Aonther question: is there any way to get more processing time assigned to a certain AI? This would speed up testing my AI significantly. Currently it's slow, and I'm optimizing it, but needing to wait a few minutes each run makes optimizing pretty annoying...
A game worth playing is a game worth modding :-)
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: File I/O in Squirrel

Post by krinn »

openttd -d ai=5 2>&1 | tee log.txt
griffin71
Traffic Manager
Traffic Manager
Posts: 142
Joined: 31 Mar 2007 13:11
Location: Amsterdam

Re: File I/O in Squirrel

Post by griffin71 »

Thanks, krinn!
(All of us have our days...)

Edit: having said that, this is Windows, and we don't support that.
Even a simple redirect of the openttd.exe output yields an empty file (let alone the use of the utility mtee, als DOS does not have a tee bult in).

What I think that happens is that the output does not go to the DOS window, because openttd opens its own DOS window, and output is sent to that window, rather that just back to the system.

Is there some debugging level that allows you not to have openttd open its own DOS window, and have the full ouput sent to the terminal (i.e. DOS prompt started openttd)?
A game worth playing is a game worth modding :-)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: File I/O in Squirrel

Post by Zuu »

There is a utility (somewhere) that convert openttd.exe from a GUI to a console program. causing ouput go to the same terminal as where it was started. IIRC it was at one of the developer's web spaces, but I don't remember whom it was.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
griffin71
Traffic Manager
Traffic Manager
Posts: 142
Joined: 31 Mar 2007 13:11
Location: Amsterdam

Re: File I/O in Squirrel

Post by griffin71 »

Zuu, did you mean the attachment by glx, Sat Sep 09, 2006 7:17 pm, found here?

What that does, is now included in openttd by default. The problem is that the console (DOS prompt window) where the output of openttd goes, is created after openttd.exe is started, and is not copyable. If I start openttd with the -d option from a command prompt, then openttd opens another command prompt where the messages go. If I don't use the -d option, there will be no messages.

-----

But to my other question,
griffin71 wrote:Another question: is there any way to get more processing time assigned to a certain AI? This would speed up testing my AI significantly. Currently it's slow, and I'm optimizing it, but needing to wait a few minutes each run makes optimizing pretty annoying...
And I remember from a few years ago, that it was quick. Calling my pathfinder caused a little pause, but then the result was there. Now it takes over 200 game days to do the same job... Has there been a fundamental change to this since openttd 0.7?
A game worth playing is a game worth modding :-)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: File I/O in Squirrel

Post by Yexo »

griffin71 wrote:And I remember from a few years ago, that it was quick. Calling my pathfinder caused a little pause, but then the result was there. Now it takes over 200 game days to do the same job... Has there been a fundamental change to this since openttd 0.7?
If by a "little pause" you mean some time where OpenTTD didn't react to any input at all, you were using an exploit that has been fixed. In some cases OpenTTD wasn't able to pause an AI. There are still a few such cases, but you'll be penalized heavily for using any of them.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: File I/O in Squirrel

Post by krinn »

you have a configurable http://wiki.openttd.org/Advanced_Settings/Competitors
look at #opcodes before AI is suspended

If i get it right how it work: AI get ticks until # of opcodes or AIController.Sleep is called.
As such, you then can make sure an hardwork will get full opcodes by forcing a pause before the hardwork
::AIController.Sleep(1); dohardwork();

Of course you will share that time with all AI so just run 1 instance and you should have maximum time for your AI

The better way is just simply: let your AI handle save with a state value, once reload AI should restart at state value saved.
That's the fastest way to let your AI work with a complex conditions requirement (you push the AI to met the conditions and save the game.

Fake results gave faster results: if you need condition A to be met, you may not need to wait the AI to met condition A, just create condition A for your AI. You can speak with your AI, AI can read its sign, and you can cheat, so switching to play as your AI you can edit your AI sign to change it, once done, your AI can now read what you asked. You'll get a sample howto do that here : http://dev.openttdcoop.org/projects/ai-aivehicletest
I think zuu's superlib could help you a lot at handling sign if you need something more evolve than aivehicletest sign handling.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: File I/O in Squirrel

Post by Yexo »

krinn wrote:Of course you will share that time with all AI so just run 1 instance and you should have maximum time for your AI
That is not true. The #opcodes is a limit per AI.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: File I/O in Squirrel

Post by krinn »

half true then :P
the less instance of AI you run, the higher you will get the hand back as you don't have to wait another AI or instance to end its opcodes cycle (or sleep call).
griffin71
Traffic Manager
Traffic Manager
Posts: 142
Joined: 31 Mar 2007 13:11
Location: Amsterdam

Re: File I/O in Squirrel

Post by griffin71 »

Point is: my AI was the only one running.

I'm completely rewriting the library now. Will take 2 months or so before it's done.
A game worth playing is a game worth modding :-)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests