AGS Pointers for Dummies: Difference between revisions

Jump to navigation Jump to search
*>Monkey 05 06
*>Monkey 05 06
No edit summary
Line 83: Line 83:


====File*====
====File*====
Another example can be seen if we look at the File type.
Another example can be seen if we look at the [http://www.bigbluecup.com/manual/File%20functions%20and%20properties.htm File] type.
 
In a system without pointers, you might have to do something like this to work with a(n external) file:
 
  int handle = FileOpen ("temp.tmp", FILE_WRITE);
  if (handle == 0) Display("Error opening file.");
  else {
    FileWrite (handle, "test string");
    FileClose (handle);
    }
 
This is difficult to work with because you have to create a new integer handle the file, use it while working with the file, and then make sure to close the file using it's handle.
 
In a system with pointers, you can do this instead:
 
  File *output = File.Open("temp.tmp", eFileWrite);
  if (output == null)
    Display("Error opening file.");
  else {
    output.WriteString("test string");
    output.Close();
    }
 
You still have to create a variable (or rather a pointer) to handle the file, but it becomes much more clear what it is for (as opposed to integers which are likely much more common in your scripts).


''Wait...what's with all this script o-name stuff?''
''Wait...what's with all this script o-name stuff?''