Placing Characters

Started by Scorpio82, Mon 09/11/2009 23:08:43

Previous topic - Next topic

Scorpio82

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.

Khris

You can code your own Extender function:

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


Use it like this:
  player.Place(100, 100);

TerranRich

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.
Status: Trying to come up with some ideas...

Scorpio82

Ah, that's an idea!  And thanks for the advice! 

ColtonPhillips

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.

TerranRich

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.
Status: Trying to come up with some ideas...

Khris

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.

TerranRich

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.
Status: Trying to come up with some ideas...

SMF spam blocked by CleanTalk