-
Notifications
You must be signed in to change notification settings - Fork 10
StringFormats
You will find many times in your game when you need to create a string
based on the values of variables, and functions like
Display
and
String.Format
allow you to do so.
AGS uses printf-style argument formatting (used by the C language). This means that you intersperse your text with special codes to insert a variable's value. These special codes begin with a percent sign, and then specify the variable type. The actual variables that you want to display are then listed afterwards.
Some examples of the special codes you can use are as follows:
Code | Description |
---|---|
%d | Integer (use to display value of int and short variables) |
%0Xd | Integer left-padded with up to X zeros |
%s | String (use to display string variables) |
%c | Character (displays the ASCII character of the supplied value) |
%f | Float (displays a float variable) |
%.Xf | Float to X decimal places |
%% | Display the percent character (i.e. no variable) |
[ | Inserts a new line into the message |
Some examples:
int life = 42;
float twoPi = Maths.Pi * 2.0;
String message = "A string variable";
Display("A normal string with no variables.");
Display("The meaning of life is %d.", life);
Display("The meaning of life in 3 digits is %03d.", life);
Display("2 times Pi is %f.", twoPi);
Display("The message says: %s.", message);
would display:
A normal string with no variables.
The meaning of life is 42.
The meaning of life in 3 digits is 042.
2 times Pi is 6.283186.
The message says: A string variable.
You can display as many variables as you like in one line:
int life = 42;
float twoPi = Maths.Pi * 2.0;
Display("Life is %d, 2 x Pi = %f, and my dinner is %s.", life, twoPi, "awful");
but, be very careful that you supply the right number of variables to correspond with the tags you use in the text. If you don't supply enough variables, your game could crash.
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