Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: AnasAbdin on Sun 07/08/2011 15:57:09

Title: Object moves only if chatacter is blocked
Post by: AnasAbdin on Sun 07/08/2011 15:57:09
frustrated...
I only want to move an object around the room (a cloud)... it works great as long as it's eBlock :S I tried eNoBlock but it just stood still...

I tried setting a timer and move the cloud pixel by pixel according to the timer... still...

here's my code:
function room_RepExec()
{
 SetTimer(1, 20);
 while ( object[0].X > 10 && IsTimerExpired(1))
 {
   object[0].X--;
   if ( object[0].X == 10 )
   {
     object[0].X = 420;
   }
 }
}


I wanted this from the first place:
function room_RepExec()
{
 if ( object[0].X < 420 )
 {
   object[0].Move(18, 90, 10, eNoBlock, eAnywhere);
      if ( object[0].X == 18 )
        {
          object[0].X = 421;
        }
 }
}


it works only when I use eBlock....
Title: Re: Object moves only if chatacter is blocked
Post by: Khris on Sun 07/08/2011 16:17:56
That function is executed 40 times per second so you're starting the timer over and over again.

Something like this should work:

function room_RepExec() {

  if (IsTimerExpired(1)) {
    oCloud.X--;
    if (oCloud.X <= 10) oCloud.X = 420;
    SetTimer(1, 20);
  }
}


Now put another "SetTimer(1, 20);" in the room's before or after fadein.

Another way:
function room_RepExec() {

  if (oCloud.X == 420) {
    oCloud.X = 419;
    oCloud.Move(18, 90, 10, eNoBlock, eAnywhere);
  }
  else if (oCloud.X == 18) oCloud.X = 420;
}


I used oCloud instead of object[0]; in room scripts, you can use an object's script name.
Title: Re: Object moves only if chatacter is blocked
Post by: AnasAbdin on Mon 08/08/2011 09:19:07
thanx man, the trick was here

oCloud.X = 419;

however, the clouds move fast even that the object speed is 1... which is the slowest but not slow enough... I'd like the speed to be much much less than that....
Title: Re: Object moves only if chatacter is blocked
Post by: Gilbert on Mon 08/08/2011 09:50:45
Since AGS V2.72 you can use negative numbers for move speeds (applies to characters and I think it applies to objects as well).
For example, -2 means 1/2 speed (every 2 frames), -3 means 1/3 speed, etc.
Title: Re: Object moves only if chatacter is blocked
Post by: Khris on Mon 08/08/2011 15:00:22
I assume you've used the second way. If you use the Timer instead, you can adjust the speed even more precisely.
Title: Re: Object moves only if chatacter is blocked
Post by: AnasAbdin on Mon 08/08/2011 17:55:09
Quote from: Khris on Mon 08/08/2011 15:00:22
I assume you've used the second way. If you use the Timer instead, you can adjust the speed even more precisely.

Yes, and yes.
I wanted them to move just slowly.. no need for nano precision here  ;)
Title: Re: Object moves only if chatacter is blocked
Post by: AnasAbdin on Sun 21/08/2011 18:58:57
I didn't wanna start another topic for this since it is the same deal...

trying to move an object but I keep getting an error that AGS cannot set the object position while it's moving...

function room_RepExec()
{
if (object[0].X == 250)
{
  object[0].X = 251;
  object[0].Move(660, 220, -2, eNoBlock, eAnywhere);
}
}


now what's going on? I used the same code in another room ( but moving the object to the other direction) and it worked:
function room_RepExec()
{
if (object[0].X == 250)
{
  object[0].X = 249;
  object[0].Move(-10, 220, -2, eNoBlock, eAnywhere);
}
}


???
Title: Re: Object moves only if chatacter is blocked
Post by: Khris on Sun 21/08/2011 23:05:41
Try 252 instead of 251.

251 might get "rounded down" to 250 (because the object is placed at 251/2 internally, which is the same as 250/2 = 125), so the first line is called again when the object is already moving.

In the other room it works because 249/2 is 124 and thus not 250/2.

The problem is the way AGS handles the coordinates in your game; recent versions of AGS started supporting native, pixel-perfect coordinates throughout the game, but highres games used to use lowres coords internally so e.g. an Object could only be placed at even coordinates.
Title: Re: Object moves only if chatacter is blocked
Post by: AnasAbdin on Mon 22/08/2011 00:01:23
worked like a charm :)
Khris... Sie sind DER Mann...  :D