Squirrel String Library

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
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Squirrel String Library

Post by Zutty »

Hi all,

This question is mainly aimed at Yexo and the other developers.

Since the Squirrel standard math library was enabled, could we also have the string library. It would be useful to have regular expressions, among other things.

I could have a go at writing a regexp parser myself (perhaps for the common library project), but before I bother I'd just like to check if the above is a possibility.

Thanks
PathZilla - A networking AI - Now with tram support.
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: Squirrel String Library

Post by Wormnest »

I know this is an old topic but I'm interested in knowing if this has ever been considered for inclusion.
Personally I would like being able to use the format function. It would help to make formatted strings easier.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: Squirrel String Library

Post by krinn »

I don't think anyone is really interrest in doing a complex output system for an API that output nothing :)
Well, ok, except GS that may output a few more now (that's still really low), NOAI output nothing by itself (to user i mean, outputing to console or signs is not really something for a user).

Try look at that lib http://dev.openttdcoop.org/projects/ailib-string
But i don't think any regex function exist, i can only think of machinweb or zuu that could have made some functions to handle strings, check their libs.
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: Squirrel String Library

Post by Wormnest »

The thing is that Squirrel already has a string library thus no one really should need to work on that. It just isn't enabled in OpenTTD.
Of course I don't know if there are parts of that library that would need to be adapted or whether there are other implications to using the library. If there are I would be interested to hear them at least.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Squirrel String Library

Post by Zuu »

1. Rethink what you want to do
OpenTTD comes with a string system with support for translations. To use it you define a string using an identifier and some text in lang/english.txt. The text can contain place holders for data. Data for the placeholders is sent to OpenTTD when you construct a GSText object or by calling AddParam on the object. Passing a company ID to the {COMPANY} placeholder makes OpenTTD automatically insert the company name for the place holder.

So for any string that are shown in the user interface should use the language file and GSText rather than raw string manipulation.

For AIs or printing debug messages in GSes, you may still want to do raw sting composing. In that case, see the available library methods below.


2. Library methods
If you still think that you want to manipulate raw strings, I've here tried to explain what SuperLib provides:

SuperLib.DataStore - contains methods to encode data into strings as well as helpers for storing strings in the name of eg. vehicles and stations (and handle the constraints by OpenTTD that station names need to be unique).

SuperLib.Helper - contains a limited set of string helpers that I've added into SuperLib for tasks not handled by the Squirrel string object itself.

Last, there is also AILib.String as pointed out above.
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 19 guests