Upgrading to new-style Strings: Difference between revisions

Jump to navigation Jump to search
Link to online manual
*>Monkey 05 06
(Link to online manual)
(2 intermediate revisions by one other user not shown)
Line 11: Line 11:


* New-style Strings have a '''capital''' 'S'! Old-style strings use a lower-case 's'.
* New-style Strings have a '''capital''' 'S'! Old-style strings use a lower-case 's'.
* New-style Strings are [[Pointers in AGS|pointer]] based. The pointer is internally managed, however new-style Strings can still hold the value '''null'''. Remember that operating on null pointers will crash your game!
* New-style Strings are [https://www.adventuregamestudio.co.uk/manual/index.html?page=ags31.htm pointer] based. The pointer is internally managed, however new-style Strings can still hold the value '''null'''. Remember that operating on null pointers will crash your game!
* As long as it is non-global (i.e., it is within a function) new-style Strings can have a default value assigned at the same time as you declare the String. Note that if you don't define a default value (or if the String is global (outside of all functions)) then it will hold the value '''null'''.
* As long as it is non-global (i.e., it is within a function) new-style Strings can have a default value assigned at the same time as you declare the String. Note that if you don't define a default value (or if the String is global (outside of all functions)) then it will hold the value '''null'''.


Line 75: Line 75:


   String new_Str = "dog";
   String new_Str = "dog";
   Display("%d", new_Str == "DoG"); // displays non-zero
   Display("%d", new_Str == "DoG"); // displays ZERO
 
Also note that the comparison operators return a boolean value unlike the comparison functions. The reason ''new_Str == "DoG"'' displays zero is because the comparison returns '''false''' which evaluates as zero numerically. This is important because this is essentially the opposite of StrComp and String.CompareTo.


===StrContains -> String.Contains===
===StrContains -> String.Contains===
Line 296: Line 298:


[[Upgrading to AGS 2.71]]
[[Upgrading to AGS 2.71]]
[[Category:Beginner Tutorials]][[Category:Scripting]]

Navigation menu