-
Notifications
You must be signed in to change notification settings - Fork 0
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 Reference
- Music and sound
- Distributing your game
- Backing up your game
- The text parser
- Translations
- Global variables
- Custom Properties
- Plugins
- Lip sync
- New Game templates
- Debugging features
- Auto-number speech files
- Integration with Windows
- Source Control integration
Engine
Scripting
- Scripting tutorial part 1
- Scripting tutorial part 2
- Pointers in AGS
- Calling global functions from local scripts
- The script header
- String formatting
- Multiple Scripts
- Understanding blocking scripts
- Dynamic Arrays
- Extender functions
- Game variables
- Predefined global script functions
- repeatedly_execute (_always)
- Custom dialog options rendering
- Built-in enumerated types
- Script language keywords
- AudioChannel functions and properties
- AudioClip functions and properties
- Character functions and properties
- DateTime functions and properties
- Dialog functions and properties
- DialogOptionsRenderingInfo functions and properties
- DrawingSurface functions and properties
- DynamicSprite functions and properties
- File functions and properties
- Game / Global functions
- 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
- Multimedia functions
- Object functions and properties
- Overlay functions and properties
- Palette functions
- Parser functions
- Region functions and properties
- Room functions
- Screen functions
- Speech functions and properties
- String functions
- System functions and properties
- Text display / Speech functions
- ViewFrame functions and properties
Working on Legacy games
Upgrading from a previous version
- Upgrading to AGS 2.7
- Upgrading to AGS 2.71
- Upgrading to AGS 3.0
- Upgrading to AGS 3.1
- Upgrading to AGS 3.2
- Upgrading to AGS 3.3
- Upgrading to AGS 3.3.5
- Upgrading to AGS 3.4
- Upgrading to AGS 3.4.1
Legal Notice
Getting in touch