Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Candle on Tue 05/07/2005 23:44:32

Title: Template for scrolling with out player .
Post by: Candle on Tue 05/07/2005 23:44:32
Anyone have one that I could see how it is done ?
Want to scroll in long rooms but won't have a player char in the room .
Title: Re: Template for scrolling with out player .
Post by: Scummbuddy on Wed 06/07/2005 00:33:54
just make sure "hide player character is ticked in the room settings area, and then I have this:


int ypos = 0;

while (ypos < 875)
{
  SetViewport(0,ypos);
  Wait(1);
  ypos++;
}

int xpos = 0;

while (xpos < 986)
{
  SetViewport(xpos, 875);
  Wait(1);
  xpos++;
}


character[EGO].ChangeRoom(1, 120, 140);


which will scroll down a long ways, and then when thats done, it will scroll to the right some, and then change rooms.
Title: Re: Template for scrolling with out player .
Post by: Candle on Wed 06/07/2005 00:42:47
Do I need the change rooms part ? I have hotspots and such for going to new rooms .
And where does that code go ?
Title: Re: Template for scrolling with out player .
Post by: Scummbuddy on Wed 06/07/2005 00:57:32
no, you dont need the new room code. and this bit of code went in my rooms interaction window->rep. exec. -> run script you may need to taylor the numbers. i doubt your room is, say, 1200 pixels high/long and 900 pixels wide.
Title: Re: Template for scrolling with out player .
Post by: Candle on Wed 06/07/2005 01:06:41
What is this part  rooms interaction window->rep. exec. -> run script I don't see that part ?is that the full name ?
My room is 800x480 .
Title: Re: Template for scrolling with out player .
Post by: Scummbuddy on Wed 06/07/2005 01:13:10
First, I'm sorry. I was wrong. I put it in my "Player enters screen (after fadein)" which is one of the many selectables underneath the "Room" tree, within the Interaction Editor. When under "Player enters screen (after fadein) you select "Run Script", and then right below it a button appears stating "Edit script", then you click on that, and then thats where the code goes.
Title: Re: Template for scrolling with out player .
Post by: Candle on Wed 06/07/2005 01:17:49
Ok I had put it there but when the room opens it likes it is doing a loop and the watch says up and the gui is grayed out and have to do a alt x and kill it to get out?
What I have .

  // script for room: Player enters screen (after fadein)
int ypos = 0;

while (ypos < 480)
{
  SetViewport(0,ypos);
  Wait(1);
  ypos++;
}

int xpos = 0;

while (xpos < 800)
{
  SetViewport(xpos, 800);
  Wait(1);
  xpos++;



Room is 800x480
Title: Re: Template for scrolling with out player .
Post by: Scummbuddy on Wed 06/07/2005 01:32:14
it shouldn't loop, but since you didnt put in the part about going to a new room, then it should just stay there, and if you want the gui not gray, but still disabled, then you need to change the setting on the game options page (the first page that pops up when ags opens)
and then in the first part of that room go to "Player enters room (before fadein) and do another run script, and do something like this:

gStatusline.Visible = false;
gIconbar.Visible = false;

mouse.Visible = false;  // works like the old HideMouseCursor

=============

and I see that you put the exact bounds of your bg into the equations I gave you earlier, but that will just add time to how long it takes, take off at least 50 pixels in both so that it "reaches" that bound faster.
Title: Re: Template for scrolling with out player .
Post by: Candle on Wed 06/07/2005 01:38:41
Ummm maybe we are not on the same track here ?
What does this script do .
I want to be able to move in the room from left to right with out a player in the room so they can click on things etc and have Interaction in the room with out a player walking around like a myst type
game .
Title: Re: Template for scrolling with out player .
Post by: Scummbuddy on Wed 06/07/2005 01:46:00
ahh, okay, im sorry. well, okay, at least you have the "hide player character" down. ok, well you will need to, in rep.exec. to check the screen coordinates to see if the mouse cursor is close, such as within 15 pixels to either side, and if so, then scroll the room over.

I haven't seen code for this myself, but that may give you some ideas to get you on your way.
Title: Re: Template for scrolling with out player .
Post by: Candle on Wed 06/07/2005 01:53:00
Ya thats kind why I wanted to see a template so I knew how to how to do it .
Maybe someone has one or knows how to do it .
Title: Re: Template for scrolling with out player .
Post by: Candle on Wed 06/07/2005 04:39:33
What do you think of this . Say i make a small ball or orb type thing that could move around the room
Like it was floating and it could give out light when needed etc ?
Something like one of these maybe
http://www.humorcafe.com/artwork/orbs.jpg
Title: Re: Template for scrolling with out player .
Post by: BorisZ on Wed 06/07/2005 22:23:37
Quote from: Candle on Wed 06/07/2005 01:53:00
Ya thats kind why I wanted to see a template so I knew how to how to do it .
Maybe someone has one or knows how to do it .

Well,  for start you can make invisible character follow mouse cursor (on rep.exec). That way your room will scroll with cursor.
If it doesn't suit you, you can try working with wievports, but it may be tricky.
Title: Re: Template for scrolling with out player .
Post by: Candle on Wed 06/07/2005 22:28:37
Quote from: BorisZ on Wed 06/07/2005 22:23:37
Quote from: Candle on Wed 06/07/2005 01:53:00
Ya thats kind why I wanted to see a template so I knew how to how to do it .
Maybe someone has one or knows how to do it .


Well, for start you can make invisible character follow mouse cursor (on rep.exec). That way your room will scroll with cursor.
If it doesn't suit you, you can try working with wievports, but it may be tricky.
Yes thats whaT I have been doing but if mouse goes over the player you see his name popup on the part of the @OVERHOTSPOT@ .. LOL
Title: Re: Template for scrolling with out player .
Post by: strazer on Wed 06/07/2005 23:18:20
First off, from the original description of your problem

Quote
Want to scroll in long rooms but won't have a player char in the room .

it was very hard to tell what kind of scrolling you actually wanted. What ScummBuddy was trying to provide you with was script for scrolling the screen across a room for a cutscene, without player interaction.

In the future, please be more specific what kind of behaviour you're actually looking for so we can help you better.

Now, how about this?:


// room script

#define SCROLL_SPEED 3
#define SCROLL_EDGE_LEFT 5
#define SCROLL_EDGE_RIGHT 5
#define SCROLL_EDGE_TOP 20
#define SCROLL_EDGE_BOTTOM 5

function room_a() { // (Room editor -> "i" -> "Repeatedly execute" -> "Edit script...")
  // script for Room: Repeatedly execute
  //...

  int newvpx = GetViewportX(); // get current viewport x-position
  int newvpy = GetViewportY(); // get current viewport y-position
  if (mouse.x > (system.viewport_width - SCROLL_EDGE_RIGHT)) newvpx += SCROLL_SPEED; // if mouse is over right scrolling edge, move new viewport x position right
  else if (mouse.x < SCROLL_EDGE_LEFT) newvpx -= SCROLL_SPEED; // if mouse is over left scrolling edge, move new viewport x position left
  if (mouse.y > (system.viewport_height - SCROLL_EDGE_BOTTOM)) newvpy += SCROLL_SPEED; // if mouse is over bottom scrolling edge, move new viewport y position down
  else if (mouse.y < SCROLL_EDGE_TOP) newvpy -= SCROLL_SPEED; // if mouse is over top scrolling edge, move new viewport y position up
  SetViewport(newvpx, newvpy); // set viewport to (new) position

  //...
}
Title: Re: Template for scrolling with out player .
Post by: Candle on Wed 06/07/2005 23:32:36
Looks nice but didn't work .
I added it to the page, check the hide player and it didn't do anything .
Title: Re: Template for scrolling with out player .
Post by: strazer on Thu 07/07/2005 01:22:39
Have you created the room_a (or room_b or room_c or ...) function first by doing
  Room editor -> "i" button -> "Repeatedly execute" -> "Edit script..."
?
If you just paste the above code into the room script like that, it isn't linked with the room interaction and isn't executed.
You have to create the interaction function first, then paste the code between the two //... in there (and the #define stuff at the top of the room script by pressing the "{}" button).

If you don't know what I just said, try renaming
  function room_a() {
to
  function repeatedly_execute_always() {
Title: Re: Template for scrolling with out player .
Post by: Candle on Thu 07/07/2005 02:01:33
Thank you , got it to work now .
Title: Re: Template for scrolling with out player .
Post by: Candle on Thu 07/07/2005 02:24:37
Quick question ? Can that be added to somewhere so I don't have to add it to every room I want to have scroll .
Title: Re: Template for scrolling with out player .
Post by: strazer on Thu 07/07/2005 02:38:41
Yes, the code should also work if you put it into the global repeatedly_execute/_always function.
Title: Re: Template for scrolling with out player .
Post by: Candle on Thu 07/07/2005 02:50:50
I added it to that part and got this error now were it work before in the room code ?
---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was in 'Global script':



Error (line 66): Expected value after '='



Do you want to fix the script now? (Your game has not been saved).

#define SCROLL_SPEED 3
#define SCROLL_EDGE_LEFT 5
#define SCROLL_EDGE_RIGHT 5
#define SCROLL_EDGE_TOP 20
#define SCROLL_EDGE_BOTTOM 5
////////////////////////////

string text;
int index;

function Save() {
  SetMouseCursor(6);
  SetTextBoxText(SAVE,1,""); // Clear Text box
  ListBoxSaveGameList(SAVE,3); // Fill List Box with saved games
  index = ListBoxGetNumItems(SAVE,3); // Count how many saved games there are           
  if (index > 19) // If saved games 20 (maximum)
    DisplayMessage(990); // Display warning
  index = 0;
  InterfaceOn(SAVE); // Bring Save interface on     
}

function Load() {
SetMouseCursor(6);
ListBoxSaveGameList(LOAD,0); // Fill List box with saved games 
InterfaceOn(LOAD); // Bring restore Interface on
}

function show_inventory_window () {
  if(game.num_inv_items > 0) { // ** CUSTOM INVENTORY WINDOW
    GUIOn (INVENTORY);    // switch to the Use cursor (to select items with)
    SetCursorMode (MODE_USE);  // But, override the appearance to look like the arrow
    SetMouseCursor (6);
    GUIOff(ICONBAR);
  }
  else DisplayMessage(996);
}

// THE REST

#sectionstart game_start  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() {
  // called when the game starts, before the first room is loaded
  CentreGUI(LOAD);
  CentreGUI(SAVE);
  CentreGUI(INVENTORY);
  }
#sectionend game_start  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
}
//////////////////////////////////////////////////
int newvpx = GetViewportX(); // get current viewport x-position
  int newvpy = GetViewportY(); // get current viewport y-position
  if (mouse.x > (system.viewport_width - SCROLL_EDGE_RIGHT)) newvpx += SCROLL_SPEED; // if mouse is over right scrolling edge, move new viewport x position right
  else if (mouse.x < SCROLL_EDGE_LEFT) newvpx -= SCROLL_SPEED; // if mouse is over left scrolling edge, move new viewport x position left
  if (mouse.y > (system.viewport_height - SCROLL_EDGE_BOTTOM)) newvpy += SCROLL_SPEED; // if mouse is over bottom scrolling edge, move new viewport y position down
  else if (mouse.y < SCROLL_EDGE_TOP) newvpy -= SCROLL_SPEED; // if mouse is over top scrolling edge, move new viewport y position up
  SetViewport(newvpx, newvpy); // set viewport to (new) position
///////////////////////////////////////////////////////////////
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

Line 66 ->  int newvpx = GetViewportX(); // get current viewport x-position
Title: Re: Template for scrolling with out player .
Post by: strazer on Thu 07/07/2005 03:17:36
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
}
//////////////////////////////////////////////////
int newvpx = GetViewportX(); // get current viewport x-position
//...

The code has to be pasted between these two braces. It's not enough to paste the code between the sectionstart and sectionend lines.
The way you have it now the code is outside of any function which cannot be done.
Title: Re: Template for scrolling with out player .
Post by: Candle on Thu 07/07/2005 03:19:05
Oh I see .
Title: Re: Template for scrolling with out player .
Post by: Candle on Thu 07/07/2005 04:18:40
Thank you for the code help strazer ...
Title: Re: Template for scrolling with out player .
Post by: strazer on Thu 07/07/2005 04:19:27
Glad I could help. :)
Title: Re: Template for scrolling with out player .
Post by: monkey0506 on Thu 07/07/2005 06:20:56
Quote from: strazer on Thu 07/07/2005 03:17:36
function repeatedly_execute() {
Ã,  // put anything you want to happen every game cycle here
}
//////////////////////////////////////////////////
int newvpx = GetViewportX(); // get current viewport x-position
//...

The code has to be pasted between these two braces. It's not enough to paste the code between the sectionstart and sectionend lines.
The way you have it now the code is outside of any function which cannot be done.

Just a thought, you may want to declare it outside of rep_ex (unless it's only called within rep_ex) (the int newvpx; part) and then just set its value in rep_ex.  Otherwise it only exists inside of rep_ex.  Also, the reason "[putting] the code...outside of any function...cannot be done" is that function calls aren't processed outside of other functions (so the function call isn't replaced by the return value).  So as long as it was inside a function it would work.  Which in this case rep_ex is the function needed...