SOLVED: Script issues w/ WALK cursor from sit view - and frame shifting prob

Started by johnny1finger, Fri 22/06/2012 19:36:29

Previous topic - Next topic

johnny1finger

Here's what I'm trying to achieve:
My game starts with cEGO sitting in a chair.  Once the game starts, the player can either interact (HAND or EYE) an object on the table next to the chair or use WALK to stand up and move freely around the room.  While cEGO is sitting, there is an animated view that shows cEGO reaching out to the table next to the chair that he's in.

Here are the problems that I am running into:
Starting out with cEGO sitting:
Code for room_load:
Code: AGS
function room_load()
{
cEGO.LockViewFrame(17, 0, 0);
}

Currently, cEGO is sitting when the game starts, however if I use the WALK cursor anywhere else in the room, the view (17) is used as cEGO moves around the room (the game crashes once loop 0 completes, since its not a standard 4 loop view for walking.  Once cEGO starts moving using the sitting view, the wait cursor is displayed and nothing else can be done.  I have found that if I unlock the view under the function room_AfterFadeIn, cEGO will stand on his own and then everything works (WALK, etc...).  I'm using:
Code: AGS
function room_AfterFadeIn
{
cEGO.UnlockView();
}


Wasn't sure if I need to use IdleView here, since an animation plays while cEGO is sitting.  Also, I thought about using a hotspot for the entire room to make cEGO stand when the WALK cursor was used, but I read in the manual or wiki that the "any click on hotspot" was for anything EXCEPT the walk icon...so I'm stuck at what I need to do from here on this piece.

Next issue is the animation while cEGO is sitting.  cEGO "shifts" when the frame is played with his arm outstretched.  The view that I'm using is 5 frames.  Using the Preview option on the view animates it correctly (no shift), however if I check the Character View (centre pivot) option, the "shift" is there.  I have tried using cEGO.LockViewAligned with all 3 alignments with no luck.

In my game's current state, I am doing everything from the room script.  I have not attempted and global scripts and/or variables.  I'm not opposed to them, it's just not a topic that I've attempted yet... I am not an experienced programmer by any definition (which I'm sure is apparent).  Everything that I have has been a self discovery process using the forums/wiki/manual.  Please accept my apologies ahead of time if I'm unclear with my explanations.

Thanks in advance for any help/advice!

-j

geork

For the walking issue:
Do you want the character to be able to move from the seated position? if not, you can use:

Code: AGS
RemoveWalkableArea(Walkable_Area_Number);


To stop him being able to move on the walkable area defined which should fix that problem. You can always use

Code: AGS
RestoreWalkableArea(Walkable_Area_Number);


To allow him to move again on that walkable area.

However, if you want him to switch back into his walking view when he is told to walk from the seated position, you're going to have to go into the global script. In GlobalScript.asc you should find the function "on_mouse_click", which does what it says on the label. Something along the lines of:

Code: AGS
function on_mouse_click(MouseButton button) {
  // Some stuff here about the game being paused
  else if (button == eMouseLeft) //this should already be there
  {
    if(Mouse.Mode == eModeWalkto && cEGO.View == 17){ //if the user clicks in walk mode and the view of the character is 17
      cEGO.UnlockView();
    }
  }
}


This will make him go back to his normal view once he is asked to walk. If you want to check whether the character is also in loop 0 and frame zero, simply put:

Code: AGS
if(Mouse.Mode == eModeWalkto && cEGO.View == 17 && cEGO.Loop == 0 && cEGO.Frame == 0)


instead of the earlier statement.

I don't know about your second problem, but I hope this solves the first one!

Khris

First of all, note that room_Load() is executed when the game switches to that room, before the fadein. This is where one "prepares" the room, e.g. starts background animations and the like, checks the status of certain objects, etc.
Then the room is faded in, and now AGS executes all the code in room_AfterFadeIn(). Usually this is where character walk a bit, e.g. through the door into the room, etc. This is also where intros or other cutscenes take place, bar some exceptions.
After that, AGS sits there and waits for player input.

Like geork explained, you have to catch the walk-click before it is handled.
You can also put an on_mouse_click into the room script though. It'll get called before the global one.
Code: ags
// add this anywhere in the room script
void on_mouse_click(MouseButton button) {
  if (button == eMouseLeft && Mouse.Mode == eModeWalkto && cEGO.View == 17) cEGO.UnlockView();
}


As for your other problem, if you need a bigger frame in an animation, expand the canvas on both sides by the same number of pixels. Characters are placed using the current sprite's bottom center, so make sure the sprites align when centered.

johnny1finger

Thanks to you both for the guidance.  I'll be implementing this shortly and will report back with the results. I'm sure it's a valid fix, assuming I use it correctly  :P

johnny1finger

Both worked great!  Thanks again for your help!!

I went with the globalscript option and added an animation of cEGO rising from his chair.  Here's my changes:

Code: AGS

if(Mouse.Mode == eModeWalkto && cEGO.View == 17)
      //if the user clicks in walk mode and the view of the character is 17
      {
        
        cEGO.LockView(14);
        //sitdown view
        cEGO.Animate(0, 7, eOnce, eBlock, eBackwards);
        //playing sitdown view in reverse for standing cEGO from seat
        cEGO.UnlockView();
      }


So does everything look clean?  Also, if I need cEGO to perform another sit/stand procedure, I should just add another if statement, with a different view, correct? (to the globalscript.asc file)

For the pixel shift, adding additional columns of pixels to offset the change worked perfectly...(took a few attempts, but all is well).

Thanks again!!!

SMF spam blocked by CleanTalk