[SOLVED] Making WalkTo and FaceDirection for all hotspots and objects

Started by tor.brandt, Thu 17/11/2016 16:59:08

Previous topic - Next topic

tor.brandt

For all handled hotspot/object event functions I specify a FaceDirection command as part of the function.

What I'd like is to make FaceDirection commands for all unhandled hotspot/object events.
I thought of making an int property for hotspots and objects, storing either 0, 1, 2, or 3 (i.e. I would have to specify a value 0-3 for each hotspot and object), and then put into the on_mouse_click function for hotspot interactions:
Code: ags
Hotspot* h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
player.FaceDirection(h.GetProperty("propDirection"));

and likewise for object interactions.

But then I realised that if I put the FaceDirection line before the ProcessClick line, then obviously the player faces the direction before he even walks to the hotspot WalkTo coordinates, whereas if I put the line after the ProcessClick line, he won't face the direction until after the unhandled event function has been carried out, which is too late. :~(

Is there some way to put the FaceDirection line "into" the ProcessClick line, such that the player first walks to the hotspot WalkTo coordinates, THEN faces the direction, and THEN carries out the rest of the unhandled event function?

Or is there another way to achieve the same result?

All suggestions appreciated!

Retro Wolf

Turn off "automatically walk to hotspots" in general settings.
Then put this line of code before your face direction code.

Code: ags
player.Walk(h.WalkToX, h.WalkToY, eBlock);


EDIT:Use eBlock for .FaceDirection too.

tor.brandt

Quote from: Retro Wolf on Thu 17/11/2016 18:31:48
Turn off "automatically walk to hotspots" in general settings.
Then put this line of code before your face direction code.

Code: ags
player.Walk(h.WalkToX, h.WalkToY, eBlock);


EDIT:Use eBlock for .FaceDirection too.

Thanks!
But then I'll have to manually put the player.Walk command into all the handled event functions, right?

Retro Wolf

I don't know what code you're using to handle clicks but when the mouse button is pressed, and there's a hotspot there then use that line of code. Have a mess around. :)

You should only have to type it once in the global script, not for every single hotspot in the game.

tor.brandt

Oooh right, no, that was just me bring stupid.
I was thinking of putting the line in the unhandled event function, but yeah, if I put it in the mouse click function it should work for both handled and unhandled events :-D

tor.brandt

Okay, so just for the future interest of anyone wanting to do the same, here's what I ended up doing:

* Uncheck "Automatically walk to hotspots in Look mode" in General Settings.

* Specify WalkToPoint for each hotspot in each room in room editor.

* Make a custom number property called "propFaceDirection" that applies to both hotspots and objects.
propFaceDirection can then have the values 0, 1, 2, or 3 - corresponding to eDirectionDown, eDirectionLeft, eDirectionRight, and eDirectionUp.
For each hotspot and object, I then set its number to correspond to the direction I want the player to face when interacting with it.

* Make two custom number properties called "propOWalkX" and "propOWalkY" that apply to objects.
For each object I then set the propOWalkX value to the x-coordinate I want the player to walk to before interacting with it.
I set the propOWalkY to the corresponding y-coordinate.

* Then in my on_mouse_click function I put:
Code: ags
if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot)
{
  Hotspot* h = Hotspot.GetAtScreenXY(mouse.x, mouse.y); //makes a pointer called "h" that points to the hotspot in question
  player.Walk(h.WalkToX, h.WalkToY, eBlock, eWalkableAreas); //gets the WalkToPoint coordinates for h, and walks the player there
  player.FaceDirection(h.GetProperty("propFaceDirection")); //gets the value from h's propFaceDirection property, and makes the player face that direction
  h.RunInteraction(mouse.Mode); //runs the function entered in the interaction function for h
}
if (GetLocationType(mouse.x, mouse.y) == eLocationObject)
{
  Object* o = Object.GetAtScreenXY(mouse.x, mouse.y);
  player.Walk(o.GetProperty("propOWalkX"), o.GetProperty("propOWalkY"), eBlock, eWalkableAreas); //gets the values from o's propOWalkX and -Y properties, and walks the player there
  player.FaceDirection(o.GetProperty("propFaceDirection"));
  o.RunInteraction(mouse.Mode);
}


You could of course do the same for characters, but then again you will probably want to make entirely custom functions for interactions with characters anyway...
Anyway, the above does the job, and thanks Retro Wolf for putting me on track about this :-D

Danvzare

Thanks for sharing, this could be quite useful for simplifying my scripts. :-D

Retro Wolf


SMF spam blocked by CleanTalk