Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Construed on Fri 20/04/2012 19:19:56

Title: This
Post by: Construed on Fri 20/04/2012 19:19:56
I'm wondering what all functions are compatible with:

This.

like This.room, This.WalkSpeed, This.player etc...
Title: Re: This
Post by: Icey on Fri 20/04/2012 20:30:59
I found this in the Manuel.


this
There are two uses for the this keyword.
1. Accessing members of the current struct

When you are creating custom structs, you use the "this" keyword inside member functions to refer to the current struct. For example:

Suppose you had this in your script header:

struct MyStruct {
  int myValue;
 
  import function MyMethod();
};

Then, in your main script, you could put this:
function MyStruct::MyMethod()
{
  this.myValue = 5;
}

The MyStruct::MyMethod tells AGS that you are defining the function MyMethod which belongs to the struct MyStruct (the :: operator means "belongs to").
The code above will mean that when the MyMethod function is called, it sets the myValue variable to 5.

2. Declaring extender functions

Please see the Extender functions page for details.
Title: Re: This
Post by: Construed on Fri 20/04/2012 21:07:33
Thanks Icy, Very intuitive explanation :D
Title: Re: This
Post by: Atelier on Fri 20/04/2012 21:09:36
Grim you can press F1 whilst in the editor to see the manual.
Title: Re: This
Post by: Icey on Fri 20/04/2012 21:15:06
No prob.