Save function?

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
Fanatik
Engineer
Engineer
Posts: 7
Joined: 17 Apr 2012 09:18

Save function?

Post by Fanatik »

Could anyone tell me what exactly is saved whenever the game saves itself? If nothing from the GS is saved automatically, is there a Class for this with a GameSave-Event or something like that? I crawled through the NoGo API but didnt find any related events :(
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Save function?

Post by planetmaker »

The gamescript doesn't save anything. Just the map state is saved and which game script, AIs and NewGRFs are in use.

EDIT: see Zuu's answer below
Fanatik
Engineer
Engineer
Posts: 7
Joined: 17 Apr 2012 09:18

Re: Save function?

Post by Fanatik »

Ok so Challenges, Achievements and such could not be carried over to a savegame... at least not without some dirty tricks ^^
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Save function?

Post by Zuu »

You need to store everything that you want to save in a table.

At loading you typically just copy the table and store it in a member variable of the GS/AI and process it later. This is because if you don't return quick enough in the Load function, OpenTTD will kill your AI/GS. Also note that there is an upper limit of how long time you are allowed to spend in the Save function.

In the TileLabels class I have added ExportToSave() and ImportFromSave member functions that allow someone using that library to gather a table representation of the library storage and then to restore it:
http://dev.openttdcoop.org/projects/gsl ... y/main.nut

In TutorialGS you can see an example of how the ImportFromSave is called:
http://dev.openttdcoop.org/projects/gs- ... n.nut#L106

Saving you find here:
http://dev.openttdcoop.org/projects/gs- ... n.nut#L232
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Fanatik
Engineer
Engineer
Posts: 7
Joined: 17 Apr 2012 09:18

Re: Save function?

Post by Fanatik »

so there are actually Load/Save Functions... looked here http://nogo.openttd.org/api/trunk/index.html and there was nothing like this. Not documented yet or is this the wrong documentation?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Save function?

Post by Zuu »

Take a look at the Save/Load article at the AI section of the wiki.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests