Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ghostlady on Sun 14/07/2024 02:58:51

Title: Move an Object to a Hotspot
Post by: Ghostlady on Sun 14/07/2024 02:58:51
I have a slider puzzle with 9 squares (hotspots) and 8 of them have an object on them. How can I create a "reset" and have all the objects go back onto the hotspots where they originally came from?
Title: Re: Move an Object to a Hotspot
Post by: Vincent on Sun 14/07/2024 09:30:42
My guess is that you can do it with variables. Like you can declare some variables outside at the top of the script:
int ObjPositionX, ObjPositionY;
Then on room_load you set the variable to be the init object position:
ObjPositionX = oObject.X;
ObjPositionY = oObject.Y;
When you need to reset then you can do the opposite:
oObject.X = ObjPositionX;
oObject.Y = ObjPositionY;
Title: Re: Move an Object to a Hotspot
Post by: Ghostlady on Mon 15/07/2024 03:53:09
Thank you Vincent for your suggestion.  I ended up doing moves.  I was looking for a quick way, like move object 1 to hotspot 1, without have to figure out the coordinates.

Wait(10);
      object[1].Move(85, 95, 5, eNoBlock, eAnywhere);
      Wait(2);
      object[2].Move(135, 95, 5, eNoBlock, eAnywhere);
      Wait(2);
      object[3].Move(185, 95, 5, eNoBlock, eAnywhere);
      Wait(2);
      object[4].Move(85, 145, 5, eNoBlock, eAnywhere);
      Wait(2);
Title: Re: Move an Object to a Hotspot
Post by: Crimson Wizard on Mon 15/07/2024 06:14:35
Hotspots have WalkToX and WalkToY properties, they are usually meant for character walking to hotspot, but you may utilize these for your purpose:

Code (ags) Select
object[1].Move(hotspot[1].WalkToX, hotspot[1].WalkToY);
Title: Re: Move an Object to a Hotspot
Post by: Ghostlady on Tue 16/07/2024 01:06:26
Nice! Thanks.