While loop never ends (SOLVED)

Started by Creator, Tue 30/03/2010 04:17:24

Previous topic - Next topic

Creator

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:

Code: ags

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?

Khris

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:

Code: ags
  int x;

  while(x < 640) {
    x += 10;
    SetViewport(x, GetViewportY());
    Wait(1); //To update the game
  }

Creator

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.

Crimson Wizard

That's strange, does this mean internal viewport coordinates do not update until end of function?

Khris

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.

SMF spam blocked by CleanTalk