Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Scorpio82 on Mon 09/11/2009 23:08:43

Title: Placing Characters
Post by: Scorpio82 on Mon 09/11/2009 23:08:43
For the longest time, I've been using this code whenever I needed to snap a character into position:

cEgo.x = 100;
cEgo.y = 100;

And I've been meaning to ask if there's a shorter way to get the same results (i.e. cEgo.xy = 100, 100;)?  The documentation doesn't seem to cover it.
Title: Re: Placing Characters
Post by: Khris on Mon 09/11/2009 23:25:24
You can code your own Extender function (http://extender%20function):

function Place(this Character*, int x, int y) {
  this.x = x;
  this.y = y;
}


Use it like this:
  player.Place(100, 100);
Title: Re: Placing Characters
Post by: TerranRich on Tue 10/11/2009 02:02:43
Just remember... if you wish there were a function that acts as a shortcut, you can always make your own. I do this all the time, and it makes things so much easier.

Also, don't forget to import this function in the global script header.
Title: Re: Placing Characters
Post by: Scorpio82 on Tue 10/11/2009 07:20:56
Ah, that's an idea!  And thanks for the advice! 
Title: Re: Placing Characters
Post by: ColtonPhillips on Tue 10/11/2009 07:42:19
by import this function in the global script header, do you actually mean import this function FROM the global script header? Because for a function like this wouldnt you put it into the global script header as it would be used in any room?

EDIT: Sorry, I guess this function would actually be in the character script woudn't it?


Quote from: TerranRich on Tue 10/11/2009 02:02:43
Just remember... if you wish there were a function that acts as a shortcut, you can always make your own. I do this all the time, and it makes things so much easier.

Also, don't forget to import this function in the global script header.
Title: Re: Placing Characters
Post by: TerranRich on Tue 10/11/2009 07:59:04
I meant to add an import statement to the global header. Something like "import function Place(this Character*, int x, int y);", if I recall correctly.
Title: Re: Placing Characters
Post by: Khris on Tue 10/11/2009 10:00:41
Quote from: ColtonPhillips on Tue 10/11/2009 07:42:19EDIT: Sorry, I guess this function would actually be in the character script woudn't it?

No, there's no such thing.
The usual place for a function like this is either GlobalScript.asc or the body of a module/additional script.
A header is meant to hold struct, enum & constant definitions and also import lines.

To make a function accessible by every room script, it's sufficient to import it like TerranRich showed.
The same thing goes for global variables, the only difference is that they also need to be exported somewhere after their declaration.
Title: Re: Placing Characters
Post by: TerranRich on Tue 10/11/2009 17:34:54
It's the "this Character*" part of the function parameters that makes this function accessible from within the Character construct (i.e. cNameOfGuy.Place(...);). Within the function, the "this" keyword alters properties and runs commands from the Character object that called the function.