Gamescript to write performance ratings into file

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
Maeron
Engineer
Engineer
Posts: 2
Joined: 02 Mar 2024 10:26

Gamescript to write performance ratings into file

Post by Maeron »

Hi,

I have decided to write a simple gamescript to save results (performance ratings + company value) to the certain file. The script should just save these values of all companies in the game at given year (2000 + 2050). But I have found problem - when I try to use standard library functions to work with files (either I/O or system), the script crashes with 'index of 'system' doesn't exist'. Can you please tell me how to fix it?

Also, does any already existing script do what I want to do?

Thank you.
skc
Traffic Manager
Traffic Manager
Posts: 177
Joined: 17 Sep 2022 02:02

Re: Gamescript to write performance ratings into file

Post by skc »

I've no knowledge of how to write OTTD GS, but I do know (from other programming help forums) that you're likely to get better assistance if you include some of your code (in particular, the line which caused this error and any lines around it for context) or upload/attach the file to your post.
There could be several ways you've got it 'wrong', and for each of them there is likely a different way to fix it.
Maeron
Engineer
Engineer
Posts: 2
Joined: 02 Mar 2024 10:26

Re: Gamescript to write performance ratings into file

Post by Maeron »

Ok, I have tried basic functions from I/O library like:

local myfile = file("test.txt","wb+");

I have tried also use different functions from standard libraries (like system from System) but it have basically same effect.

I have found the forum post from 2009 (viewtopic.php?t=42622), where people claim that standard libraries are not included in OpenTTD. Is that still true? If yes, is there another way to do it except for manual writing of data after end of the game?

Thanks
agentw4b
Traffic Manager
Traffic Manager
Posts: 216
Joined: 14 Apr 2017 15:51
Location: Czech Republic

Re: Gamescript to write performance ratings into file

Post by agentw4b »

I think it's blocked on purpose.
You can do a little magic with saving logs or sending data through the so-called Admin port as JSON, but it's hard for non-programmers.


The Gamescript Library could theoretically be used for text data input, because this data is searched for in Openttd/Game/library as well as in Openttd/Content_download/game/library, so even a packed gamescript in tar format could access external data in this way. For example, to import the location of cities ... But for the output, there is nothing left but to save the logs and then somehow parse the logs using an external program.
Owner and admin of servers with names "Experimental games" .
My heightmaps: Flat Earth Map and United nations logo
My scenarios: Game Fallout 1,2,3 Map scenario
My gamescripts: City Founder GS
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 19 guests