File I/O in Squirrel
Moderator: OpenTTD Developers
File I/O in Squirrel
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?
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 

Re: File I/O in Squirrel
A game worth playing is a game worth modding 

Re: File I/O in Squirrel
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.
Re: File I/O in Squirrel
start openttd with -d ai=5
and you'll get the log in your console
and you'll get the log in your console
Re: File I/O in Squirrel
Thanks! But how dow I copy from the console?krinn wrote:start openttd with -d ai=5
and you'll get the log in your 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 

Re: File I/O in Squirrel
openttd -d ai=5 2>&1 | tee log.txt
Re: File I/O in Squirrel
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)?
(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 

Re: File I/O in Squirrel
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)
Junctioneer (a traffic intersection simulator)
Re: File I/O in Squirrel
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,
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,
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?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...
A game worth playing is a game worth modding 

Re: File I/O in Squirrel
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.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?
Re: File I/O in Squirrel
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.
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.
Re: File I/O in Squirrel
That is not true. The #opcodes is a limit per AI.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
Re: File I/O in Squirrel
half true then 
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).

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).
Re: File I/O in Squirrel
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.
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 

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