Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arj0n on Sat 24/07/2010 08:01:20

Title: [Solved] Set left-X and right-X bounderies for moving object
Post by: arj0n on Sat 24/07/2010 08:01:20
Object should only be allowed to move when object.x is withing 20 and 530 [having the object horizontal size: 90].
Horizontal room size: 640.

This doesn't seem to work...:

function Block_AnyClick()
{
 Object* myobject = Object.GetAtScreenXY(mouse.x, mouse.y);
 if ((myobject.X <=530 && myobject.ClickedRightHalf())) myobject.Move(myobject.X+100, myobject.Y, 10, eBlock, eAnywhere);
 //move left
 else if (myobject.X >=20)  myobject.Move(myobject.X-100, myobject.Y, 100, eBlock, eAnywhere);
 //move right
}
Title: Re: Set left-X and right-X bounderies for moving object
Post by: GarageGothic on Sat 24/07/2010 08:49:32
Your "else" runs even if only the <= part fails, so instead try:

function Block_AnyClick()
{
  Object* myobject = Object.GetAtScreenXY(mouse.x, mouse.y);
  if ((myobject.X <=530 && myobject.ClickedRightHalf())) myobject.Move(myobject.X+100, myobject.Y, 10, eBlock, eAnywhere);
  //move left
  else if (myobject.X >=20 && !myobject.ClickedRightHalf())  myobject.Move(myobject.X-100, myobject.Y, 100, eBlock, eAnywhere);
  //move right
}
Title: [Solved] Set left-X and right-X bounderies for moving object.
Post by: arj0n on Sat 24/07/2010 08:57:16
The object is still moving through its bounderies...

Edit: changed the <='number' and the >='number' , now it works.