Scripting, Code & Interaction: Difference between revisions
→GlobalInts, your friend: what they are and how to use them
Line 148: | Line 148: | ||
==GlobalInts, your friend: what they are and how to use them== | ==GlobalInts, your friend: what they are and how to use them== | ||
''What are GlobalInts and how would I use them? '' | |||
'''GlobalInts''', or Global Integers, are a set of 100 variables that can be accessed anywhere in the game using script. You may set a globalint with '''SetGlobalint()''' and get the value of one with '''GetGlobalInt()'''. | |||
SetGlobalInt(int variablenumber, int value); | |||
Example: '''SetGlobalInt(47, 20);''' will set global int #47 with a value of 20. | |||
GetGlobalInt(int variablenumber); | |||
Example: '''GetGlobalInt(47);''' will ''return'' the value stored in global int #47. Note that this is not a complete command. Treat this like you would with a variable: set it to something, or display it somehow. Use it as the object of a command, in other words. | |||
To alter the value of a globalint, use functions ''ONLY''. Don't use operators like '''++''' and '''+=''' to increment or decrement the value of the global int. Use the following: | |||
SetGlobalInt(47, GetGlobalInt(47) + 1); // adds 1 to the global int #47 | |||
SetGlobalInt(47, GetGlobalInt(47) - 1); // subtracts 1 from global int #47 | |||
SetGlobalInt(47, GetGlobalInt(47) + 12); // adds 12 to the global int #47 | |||
Keep in mind that globalints are just like any other int variable. There are also '''GlobalStrings'''. Look 'em up. :) | |||
==Error: "(line xyz): incorrectly terminated character constant"== | ==Error: "(line xyz): incorrectly terminated character constant"== | ||
==Slowing down your loops== | ==Slowing down your loops== |