Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Creator on Tue 30/03/2010 04:17:24

Title: While loop never ends (SOLVED)
Post by: Creator on Tue 30/03/2010 04:17:24
I'm making a title screen in AGS 3.1.2 SP1 which scrolls to "another screen" (in reality the room is just double the X size of the room width set in general settings which is 640x400).
When I try to scroll to the "other screen" I use a while loop to set the X coordinate of the viewport using:


while(GetViewportX() < 641)
{
 SetViewport(GetViewportX()+10, GetViewportY());
 Wait(1); //To update the game
}


Yet, even when the X of the viewport is at 650, the while loop still executes.
Any reason why?
Title: Re: While loop never ends
Post by: Khris on Tue 30/03/2010 08:29:14
Never as in never, or never as in doesn't when I want it to?

The Viewport's X coord starts out at 0, so when it reaches 640, the while loop runs one last time, setting it to 650.

Use
  while (GetViewPortX() < 640)

If it doesn't work at all, use a variable:

  int x;

  while(x < 640) {
    x += 10;
    SetViewport(x, GetViewportY());
    Wait(1); //To update the game
  }
Title: Re: While loop never ends
Post by: Creator on Tue 30/03/2010 13:25:04
Quote from: Khris on Tue 30/03/2010 08:29:14
Never as in never, or never as in doesn't when I want it to?

Never as in never (if I took out the wait it caused an error, saying the while loop ran 150001 times).
Using the variable works (with 641), and changing the condition to 640 instead of 641 works too (without the variable).

Thanks for your help Khris.
Title: Re: While loop never ends (SOLVED)
Post by: Crimson Wizard on Tue 30/03/2010 14:12:47
That's strange, does this mean internal viewport coordinates do not update until end of function?
Title: Re: While loop never ends (SOLVED)
Post by: Khris on Tue 30/03/2010 14:40:41
No, but with 641, the loop called SetViewPort(650, ...); and AGS won't let that happen (in this case). Thus it's back to 640 and the loop continues forever.