First of all allow me to explain what's wrong with the example code you give. At runtime, AGS first executes user scripts that queue up commands that are later executed by the engine. So when you put a SetViewport() function in a while loop, your script will continue executing while it iterates through the loop. The engine will only see and execute the last SetViewport() command. To achieve the scroll effect you seek it is necessary for your "while loop" to span multiple game scans. This can be achieved using the repeatedly execute event as follows.
Create a GUI named gMsg that contains a label named gMsgLabel. The add the following code to your room. I don't have access to an AGS workstation at the moment so I can't test anything. However, I think there is enough here to give you and idea of what needs to be done.
Code: ags
Create a GUI named gMsg that contains a label named gMsgLabel. The add the following code to your room. I don't have access to an AGS workstation at the moment so I can't test anything. However, I think there is enough here to give you and idea of what needs to be done.
// Scroll Room variables
#define MAX_DELAY 1
int delay=0;
int xpos=0;
// Display message variables
#define MAX_MSG 10
#define MAX_MSGTIME 100
int msgtime=0;
int msgid=0;
function room_RepExec() {
// Scroll Room
delay++;
if (delay>MAX_DELAY) {
delay = 0;
if (xpos<640) {
xpos++;
SetViewport(xpos, 0);
}
}
// Enable message GUI
if (msgid<MAX_MSG) gMsg.Visible = true;
else gMsg.Visible = false;
// Display Messages
msgtime++;
if (msgtime>MAX_MSGTIME) {
msgtime = 0;
msgid++;
if (msgid=1) gMsgLabel.Text = "Message-1";
else if (msgid=2) gMsgLabel.Text = "Message-2";
else if (msgid=3) gMsgLabel.Text = "Message-3";
:
else if (msgid=N) gMsgLabel.Text = "Message-N";
}
}