Page 1 of 1

Gamescript to write performance ratings into file

Posted: 02 Mar 2024 10:32
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.

Re: Gamescript to write performance ratings into file

Posted: 03 Mar 2024 06:22
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.

Re: Gamescript to write performance ratings into file

Posted: 03 Mar 2024 10:15
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

Re: Gamescript to write performance ratings into file

Posted: 03 Mar 2024 10:17
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.