AGS Pointers for Dummies: Difference between revisions

Jump to navigation Jump to search
*>Monkey 05 06
*>Monkey 05 06
Line 259: Line 259:


The above example was originally written and designed around the 2.7x branch of AGS. As of AGS 3.0 however, we have the ability to use extender methods. For this particular example, I would recommend adding global extenders such as Character.GetHealth and Character.SetHealth instead of using a separate structure globally. You could still use the structure inside of your script (perhaps in a different script, where the extenders would actually be defined), but it would make it simpler to integrate your extensions into existing scripts by using extenders instead. Check them out if you're using a 3.x version of AGS!
The above example was originally written and designed around the 2.7x branch of AGS. As of AGS 3.0 however, we have the ability to use extender methods. For this particular example, I would recommend adding global extenders such as Character.GetHealth and Character.SetHealth instead of using a separate structure globally. You could still use the structure inside of your script (perhaps in a different script, where the extenders would actually be defined), but it would make it simpler to integrate your extensions into existing scripts by using extenders instead. Check them out if you're using a 3.x version of AGS!
==Dynamic Arrays Are Pointers Too==
In addition to the managed types, there are another type of pointer you should be aware of: {{link|Dynamic Arrays||dynamic arrays}}. You can create a dynamic array of the base types (such as int) or of pointers to a managed type (such as Character*). For creating a dynamic array of pointers, see {{link||Dynamic Array of Pointers}}.
Unlike the managed types, you use the '''new''' keyword to create a new array dynamically. The name you give it is treated as a pointer. The manual gives us this example:
  int characterHealth[];
  characterHealth = new int[Game.CharacterCount];
Initially, ''characterHealth'', just as with other pointers, holds the value of '''null'''. When you assign its value on the second line, you are telling it, as with other pointers, to point to the array that you've newly created.
This is particularly important if you pass a dynamic array as a function parameter. If you change the value of a dynamic array passed as a function parameter, it will change the value of the array itself. Keep in mind that the parameter is pointing to the same array as what you passed into the function. Very useful if it's what you want, but it can be confusing if you're not aware why it's happening.


=Closing=
=Closing=
Anonymous user

Navigation menu