Escaping characters: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1: Line 1:


When you manage your AGS Strings, you might want to pay special attention to those two characters:
When you manage your AGS Strings, you might want to pay special attention to these characters:
* '''"''' (double quote)
* '''"''' (double quote)
* '''\''' (backslash)
* '''\''' (backslash)
* '''[''' (opening square bracket, also known as left brace)
* '''[''' (opening square bracket, also known as left brace)
* '''%''' (percent symbol)


For easy solutions, simply read [[String_formatting#Displaying_special_characters]]. For thourough explanations, read below.
For easy solutions, simply read [[String_formatting#Displaying_special_characters]]. For thourough explanations, read below.
Line 12: Line 13:
| '''How to read this walkthrough'''
| '''How to read this walkthrough'''
There are 3 stages in managing your strings :  
There are 3 stages in managing your strings :  
* 1) How you type them into the '''Editor'''
# How you type them into the '''Editor'''
* 2) How they will actually be stored into the engine's '''memory''', at runtime
# How they will actually be stored into the engine's '''memory''', at runtime
* 3) How they will be '''rendered''' into the display: in a ''Label'', in a ''Listbox'', or in a ''Display'' command.
# How they will be '''rendered''' into the display: in a ''Label'', in a ''Listbox'', or in a ''Display'' command.
|}
|}


Line 50: Line 51:
The first two backslashes become just "\", "\[" stays "\[", "\b" becomes just "b".
The first two backslashes become just "\", "\[" stays "\[", "\b" becomes just "b".
Tricky, isn't it?
Tricky, isn't it?
|-
| '''Any number of percent symbols'''  || String s = "aaa%bbb"; ''or'' String s="aaa%%bbb"; || 97 97 97 37 98 98 98  or 97 97 97 37 37 98 98 98 || The string will be stored in memory exactly as you typed it in. Trouble may arise only if you decide to use that particular String as the first parameter of the ''String.Format'' or ''Display'' function.
|}
|}


Line 81: Line 84:
|-
|-
| aaa\\\\bbb || aaa\\\\bbb || (identical) See Label rendering rules.
| aaa\\\\bbb || aaa\\\\bbb || (identical) See Label rendering rules.
|-
| aaa%bbb || aaa%bbb || The percent symbol is rendered identically when displayed in a Label.Text.<br> Remember, though, that it has a special effect only when used as the first parameter of the ''String.Format'' or ''Display'' function (read the next section).
|}
|}


Line 101: Line 106:
| aaa\\\\bbb || aaa\\\\bbb || The string gets rendered exactly as in memory, as the backslashes are not followed by '''['''.
| aaa\\\\bbb || aaa\\\\bbb || The string gets rendered exactly as in memory, as the backslashes are not followed by '''['''.
|-
|-
| aaa%bbb || ? || That's not correct. '%' is a special character meant for formatting Strings, as in ''String s = String.Format("The value of i is %d", i);''. Why would you try to render ''%b'' in a Label?
| aaa%ddd || '''In Label.Text:''' aaa%ddd<br>'''In Display:''' aaa%?dd ''(where ? could be any character)'' || '''%''' is a special character meant for formatting Strings, as in ''String s = String.Format("The value of i is %d", i);''.<br>In Labels, it will have no effect. However the ''Display'' function works the same way as ''String.Format'', so you must avoid having a single percent symbol. Use double percents instead.
|-
| aaa%%ddd || '''In Label.Text:''' aaa%%ddd<br>'''In Display:''' aaa%ddd || '''%''' is a special character meant for formatting Strings, as in ''String s = String.Format("The value of i is %d", i);''.<br>In Labels, it will have no effect. However the ''Display'' function works the same way as ''String.Format'', so if you want to display ''one'' percent symbol, you must have ''two'' in your string.
|-
|-
| aaa%%bbb || aaa%bbb || A double percent in memory is rendered as a single percent on-screen
| aaa%%bbb || aaa%bbb || A double percent in memory is rendered as a single percent on-screen
|}
|}


<big>'''3) At runtime, in a Listbox'''</big>
The string is rendered exactly as it is stored in memory. the Listbox doesn't handle line breaks, so a '''[''' or a '''\[''' in memory will appear as-is in the Listbox.


<big>'''WARNING: This page is still being redacted.'''</big>
But remember this :
* If your string contains ''one'' percent symbol, it can cause issues if at some stage before rendering it's used in a ''String.Format'' function (see previous section for recommendations about the double-percents)
* If your string contains several '''\''' followed by one '''[''', then all the '''\''' will be deleted from memory if your string gets manipulated by any String-manipulation function (Append, AppendChar, etc.). See previous section to know more.


[[Category:Scripting]][[Category:Advanced Tutorials]]
[[Category:Scripting]][[Category:Advanced Tutorials]]
132

edits

Navigation menu