-
Notifications
You must be signed in to change notification settings - Fork 9
UpgradingTo271
AGS 2.71 adds new simple string support to the scripting language. Strings have long been a pain to use in AGS, but this is finally addressed by v2.71.
There's a new String type (that's a capital 'S'). These new strings
behave like Java/C#
strings in that you can easily assign to and
manipulate them.
For example, in 2.7 and previous versions, you had to do this:
string text;
StrCopy(text, "This is my text");
in 2.71, you can now do:
String text = "This is my text";
Furthermore, the == and != operators can be used to compare strings for equality (equivalent to using StrComp but much more intuitive). An additional benefit is that there is no longer a need for GetText() and SetText() methods -- instead, we can now just have Text properties.
All the old-style functions that took a "string buffer" parameter have now been replaced with new ones that return a string instead. Where properties have been created, you should be able to use them like any other property, so:
lblLabel.Text = "Hello";
String buttonValue = btnOK.Text;
and so on.
NOTE: Some of the new functions are provided on the Game object --
for example, the new GetSaveSlotDescription function needs to be called
like this:
String description = Game.GetSaveSlotDescription(10);
This is part of a move towards all built-in functions being
object-based, but watch out for it as it could well cause some
confusion. The manual will show you which functions require this.
Rather than using old functions like StrCat and StrContains, you now call the functions directly on the strings:
String text = "Hello";
text = text.Append("World");
will mean that text now contains "HelloWorld".
Note the text = in that expression. Functions like Append will
return a modified version of the string, they won't actually change the
original. Therefore, to update the text variable you need to assign
the result to it.
Backwards compatibility
In order to maintain backwards compatibility, a new "const" keyword has been added. This applies only to old-style strings, and allows them to interoperate with the new ones. A new-style String can be passed to a function that expects a "const string" (which means that it will not be allowed to change the string's contents), but cannot be passed to a function that expects a "string" (since it could overwrite the string data and mess things up).
So, you may find that any custom functions you have that take a string parameter stop working. If this is the case, change the parameter from "string" to "const string" and that should fix it.
Apologies for the inconvenience, but this is the only way to allow new Strings to interoperate safely with old-style strings.
Getting Started in AGS
Editor
- New Game templates
- Editor Preferences
- General Settings
- Default Setup
- Colours Editor
- Room Editor
- Character Editor
- Cursor Editor
- Dialog Editor
- Font Preview
- GUI Editor
- Inventory Items Editor
- View Editor
- Sprite Manager
- Music and sound
- Voice speech
- Script Modules
- System limits
- Log Panel
- Plugins
- Other Features
Engine
Scripting
- Scripting Tutorial
- Scripting Language
-
Scripting API
- Script API Overview
- Standard Constants
- Standard Enumerated Types
- Standard Types
- Game variables
- Global arrays
- Global event handlers
- repeatedly_execute / repeatedly_execute_always
- Custom dialog options rendering
- Global functions: general
- Global functions: message display
- Global functions: multimedia actions
- Global functions: palette operations
- Global functions: room actions
- Global functions: screen effects
- Global functions: wait
- AudioChannel functions and properties
- AudioClip functions and properties
- Camera functions and properties
- Character functions and properties
- DateTime functions and properties
- Dialog functions and properties
- DialogOptionsRenderingInfo functions and properties
- Dictionary functions and properties
- DrawingSurface functions and properties
- DynamicSprite functions and properties
- File functions and properties
- Game functions and properties
- GUI functions and properties
- GUI control functions and properties
- GUI Button functions and properties
- GUI InvWindow functions and properties
- GUI Label functions and properties
- GUI List Box functions and properties
- GUI Slider properties
- GUI Text Box functions and properties
- Hotspot functions and properties
- Inventory item functions and properties
- Maths functions and properties
- Mouse functions and properties
- Object functions and properties
- Overlay functions and properties
- Parser functions
- Region functions and properties
- Room functions and properties
- Screen functions and properties
- Set functions and properties
- Speech functions and properties
- String functions
- System functions and properties
- TextWindowGUI functions and properties
- ViewFrame functions and properties
- Viewport functions and properties
- Obsolete Script API
- Event Types
- Key code table
- Audio in script
Legal Notice
Getting in touch
Misc