[SMALL SUGGESTION] cEgo.Teleport

Started by subspark, Fri 04/09/2009 11:48:20

Previous topic - Next topic

subspark

I was looking for a way to pop a character in at certain coordinates but could not make effective use of player.Move until I realised that wasn't the code I was looking for. The code to do this as suggested in the manual is unessecarily cumbersome and is one of the few remaining things to be formatted to the new scripting style.

Instead of:

Code: ags
cEgo.x(25);
cEgo.y(50);
cEgo.PlaceOnWalkableAreas();


How about:

Code: ags
cEgo.Teleport(x,y,eNoBlock, eWalkableAreas);


Or, if you want it by-the-book:

Code: ags
cEgo.Place(x,y,eNoBlock, eWalkableAreas);


It's much nicer to work with don't you think. :)

Cheers,
Sparky.

Akatosh

That can be very easily accomplished via a custom function. Or, if you want to cheat, you could do this:

Code: ags

player.ChangeRoom(player.Room, 25, 50);
player.PlaceOnWalkableAreas();

Scavenger

Here's that custom function.

Code: ags

function Place (this Character*,int x, int y, char onwalkablearea) //I can't remember eAnywhere's enum name.
{
this.x = x;
this.y = y;
if (onwalkablearea) this.PlaceonWalkableAreas ();
}


Remember: if it can be achieved through code with any kind of speed, it's probably best as a custom function.

monkey0506

Scavenger you may want to add check Character.Moving just in case someone calls the function while the character is already walking. And the enum's name is WalkWhere, though just like BlockingStyle it doesn't really make sense. A simple bool(ean) value would be a better, more logical fit.

Code: ags
function PlaceAtRoomXY(this Character*, int x, int y, bool onWalkableArea) {
  if (this.Moving) this.StopMoving();
  this.x = x;
  this.y = y;
  if (onWalkableArea) this.PlaceOnWalkableArea();
}

// header.ash
import function PlaceAtRoomXY(this Character*, int x, int y, bool onWalkableArea=false);


I also think PlaceAtRoomXY better meshes with the naming conventions of the existing functions.

On a slightly related note, does anyone else find it interesting that for Characters, Hotspots, and Objects we only check SCREEN co-ordinates but for Regions we only check ROOM co-ordinates? It would seem logical to me to have functions to check both (though they would of course be easy to script if needed using GetViewportX and GetViewportY).

Khris

Quote from: monkey_05_06 on Fri 04/09/2009 17:25:46On a slightly related note, does anyone else find it interesting that for Characters, Hotspots, and Objects we only check SCREEN co-ordinates but for Regions we only check ROOM co-ordinates? It would seem logical to me to have functions to check both (though they would of course be easy to script if needed using GetViewportX and GetViewportY).

I guess it's because you usually check for characters, hotspots or objects at the mouse position and for regions at a character's or object's position.
I'm not sure it's the best way to go to introduce lots of functions that aren't really necessary/can be easily scripted by oneself.

Kweepa

Since the user has to find a problem with just setting the xy coords, find the workaround in the manual, find some inconsistencies, do a forum search and hopefully find this thread, then edit the global scripts, just to do something pretty common, I think the original suggestion makes sense. Then it's autocomplete to the rescue!
Still waiting for Purity of the Surf II

subspark

Thus the point of my suggestion is hilighted. ;)
Cheers,
Sparky

Akatosh

Not really. The custom function is really just for convenience's sake. All you have to do is to find out you can set the x and y coordinates directly, and that shouldn't be too hard, even for a beginner.

Pumaman

I suppose it wouldn't do any harm to add this as a built-in function, though it's not a priority at the moment. :)

SMF spam blocked by CleanTalk