Scripting, Code & Interaction: Difference between revisions
Scripting, Code & Interaction (view source)
Revision as of 13:42, 19 September 2007
, 19 September 2007→Inserting variables into speech/messages
*>Ashen |
*>Ashen |
||
Line 176: | Line 176: | ||
This could also be done with strings. For example, if the player's name is stored in the '''global string''' #17, use the following code if you want '''BOB''' to call your character by name: | This could also be done with strings. For example, if the player's name is stored in the '''global string''' #17, use the following code if you want '''BOB''' to call your character by name: | ||
String my_name = Game.GlobalString[17]; | |||
cBob.Say("Hey, '''%s'''! What's goin' down, my man?", my_name); | |||
Confused? First, we declare a String and name it '''my_name'''. Next, we use '''Game.GlobalString''' to store the string in slot #17 into the String we created. Next, '''Character.Say''' will be used and the '''%s''' is replaced with the string '''my_name'''. Got it? | |||
You can also do this with int variables, e.g. to display numbers on GUI Labels: | |||
int my_int = 3; | |||
String my_string = String.Format("'''%d"''', my_int); | |||
Or: | |||
int my_int = player.InventoryQuantity[iCheese.ID]; | |||
player.Say("I have '''%d''' pieces of cheese.", my_int); | |||
(The last one could be shortened to: ''player.Say("I have '''%d''' pieces of cheese.", player.InventoryQuantity[iCheese.ID]);'') | |||
'''NOTE:''' | |||
* The ''Game.GlobalString'' array was introduced in V2.71. In earlier versions, you'll need to use ''GetGlobalString'' | |||
* ''Character.Say'' was introduced in V2.7, earlier versions use ''DisplaySpeech'' | |||
* For more on String formatting codes (like ''%d'' and ''%s''), [http://www.bigbluecup.com/manual/StringFormats.htm read the manual]. | |||
==GlobalInts, your friend: what they are and how to use them== | ==GlobalInts, your friend: what they are and how to use them== |