GSGoal Hidden limit
Posted: 12 Jan 2013 00:31
I've discovered that there's a limit of 255 goal objects in total using the GSGoal interface. (Calling GSGoal.New() 256 times yields a problem) It took me about an hour of digging through openTTD's code base to actually find this, so let's state the following for the record:
This limit is mentioned nowhere in the API. It should probably be mentioned as it can quite lead to problems. There is also no communication to the script whatsoever as to the status of this limit, so the gamescript writer is forced to either book-keep himself, which is double-counting something that needn't be, or forced to be left guessing. Also, the behaviour when creating the 256th-object is unknown to me, and also undocumented. Furthermore, if a gamescript that uses goals is hoped to be included in another gamescript, that second gamescript has to incorporate the former's counting into its own, and this will quickly get messy, especially with libraries around using Goal objects.
And, last but not least, it maybe a bit low of a limit. Sure, in a game with one company most scripts will not reach this number. But with, say, 16 companies, even keeping a simple score list, or a goal for each (rival) company that exists, is all but impossible due to 16*16 = 256 > 255.
If I wanted to have a goal for each cargo type, that's 32 * 16 = 512, also more.
This limit is mentioned nowhere in the API. It should probably be mentioned as it can quite lead to problems. There is also no communication to the script whatsoever as to the status of this limit, so the gamescript writer is forced to either book-keep himself, which is double-counting something that needn't be, or forced to be left guessing. Also, the behaviour when creating the 256th-object is unknown to me, and also undocumented. Furthermore, if a gamescript that uses goals is hoped to be included in another gamescript, that second gamescript has to incorporate the former's counting into its own, and this will quickly get messy, especially with libraries around using Goal objects.
And, last but not least, it maybe a bit low of a limit. Sure, in a game with one company most scripts will not reach this number. But with, say, 16 companies, even keeping a simple score list, or a goal for each (rival) company that exists, is all but impossible due to 16*16 = 256 > 255.
If I wanted to have a goal for each cargo type, that's 32 * 16 = 512, also more.