Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: Volklaw on Mon 14/05/2018 13:42:25

Title: How to make character stand still and not move when the screen is clicked
Post by: Volklaw on Mon 14/05/2018 13:42:25
Hi Everyone

This is my second beginners question. I've looked a lot at similar questions in the forums but I'm still having an issue
I am basically trying to get cEgo to walk up a ladder and then be rendered incapable of any movement at the top of the ladder.
My initial idea was to have the animation where he gets to the top of the ladder finish and then remove all walkable areas immediately afterwards.

Although this mostly works, by which I mean he cannot walk anywhere; I have noticed that when cEgo is at the top of the ladder and I use the "walk to" (footsteps) icon of the gui to click anywhere on the screen, that this then moves him back to the first frame of the animation where he is at the bottom of the ladder. Again, he cannot move from here but he it doesn't look great and if he interacts with the ladder again it plays him going down the ladder even though he is at the bottom. At this point he is free to walk again.

Please see below
PS. You will notice I am creating bools that are essentially true and false aspects of each other. I am not very experienced at this and have run into problems where by, declaring that something happens IF a bool = false, the action/event doesn't work. I'm certain there is an easier way to do this but it eludes me. Any advice on this generally will also be greatly appreciated.


//Climbing ladder animation
function oLadderUsed_Interact()
{
if (NotOnLadder) {
cEgo.Walk(251, 378, eBlock);         // cEgo is walking to the coordinates where the animation (climbing) will begin[/color]
cEgo.LockView(3);
cEgo.Animate(0, 1, 0, eBlock, eForwards);
RemoveWalkableArea(1);               // cEgo is now at top of ladder
NotOnLadder = false;
OnLadder = true;
}
else
{
cEgo.LockView(3);                    // Process of animation is reversed
cEgo.Animate(0, 1, 0, eBlock, eBackwards);
RestoreWalkableArea(1);
cEgo.UnlockView(3);
NotOnLadder = true;
OnLadder = false;
Title: Re: How to make character stand still and not move when the screen is clicked
Post by: Cassiebsg on Mon 14/05/2018 14:14:47
Okay, first thing is to get the [ code ] tag in there so we can see the code properly.


//Climbing ladder animation
function oLadderUsed_Interact()
{
    if (NotOnLadder) {
        cEgo.Walk(251, 378, eBlock); // cEgo is walking to the coordinates where the animation (climbing) will begin[/color]
        cEgo.LockView(3);
        cEgo.Animate(0, 1, 0, eBlock, eForwards);
        RemoveWalkableArea(1); // this is only needed if walkable area 1 reaches the chords where your character is now.
        NotOnLadder = false;
        OnLadder = true;
        }
    else
    {
        cEgo.LockView(3);                    // Process of animation is reversed
        cEgo.Animate(0, 1, 0, eBlock, eBackwards);
        RestoreWalkableArea(1);
        cEgo.UnlockView(3);
        NotOnLadder = true;
        OnLadder = false;
} // ] <-- did you type this or copy/pasted your code? Cause this character should not be here I have closed the function now with the }


EDIT: Let me now try to fix/explain a few things.


//Climbing ladder animation
function oLadderUsed_Interact()
{
    if (NotOnLadder) { // I rather like to make my bools start with isPlayerOnLadder, as it automatically tells me it's a question with only false/true as answers. But this is also fine. Assuming your global variable is then set to true.
        cEgo.Walk(251, 378, eBlock);         // cEgo is walking to the coordinates where the animation (climbing) will begin
        cEgo.LockView(3);
        cEgo.Animate(0, 1, 0, eBlock, eForwards);
        RemoveWalkableArea(1);               // cEgo is now at top of ladder
        NotOnLadder = false; // good.
        // OnLadder = true; (this is not needed)
        cEgo.UnlockView(); // <-- this is needed, and the reason it'll then show the first frame at the bottom of the ladder. also you might want to create a view with the character at the top of the ladder (the one with just the last frame so you can change to that view instead).

        }
    else // this means that you are on top of the ladder
    {
        cEgo.LockView(3);                    // Process of animation is reversed
        cEgo.Animate(0, 1, 0, eBlock, eBackwards);
        RestoreWalkableArea(1);
        cEgo.UnlockView(3);
        NotOnLadder = true;
    }
}


Note, if you need the negative of a bool variable you just use ! in front of it's name.
As in if (NotOnLadder) this is true and if (!NotOnLadder) is false.
Title: Re: How to make character stand still and not move when the screen is clicked
Post by: Monsieur OUXX on Mon 14/05/2018 15:31:06
another approach : try this as a proof of concept in your global script and then if it works try to make it cleaner by moving it to your room script :



bool isOnTopOfLadder = false;

void blockWalking()
{
   if (player.Room == /* the room where it's supposed to blok */)
   {
       isOntopOfLadder = /* conditions to return true if he's supposed to be on top of ladder */;

       if(isOnTopOfLadder)
       {
           if(player.Moving)
           {
               player.StopMoving();
           }

           //Do this only if needed
           player.LockView(/* the view wheree stands still at the top of te ladder */);
       }
    }
}

//block the walk at the beginning of the game loop
void repeatedly_execute_always()
{
    blockWalking();
}

//block the walk at the end of the game loop too (just in case)
void late_repeatedly_execute_always()
{
    blockWalking();
}


Title: Re: How to make character stand still and not move when the screen is clicked
Post by: Khris on Mon 14/05/2018 23:28:16
To intercept room clicks, you can add an on_mouse_click function to your room script. If one exists, AGS calls it before the global one, and if you run ClaimEvent() in it, the global click processing is skipped entirely.

Here's an example that prevents walking when the player has climbed the ladder:
function on_mouse_click(MouseButton button) {
  if (!OnLadder) return; // not on ladder, standard rules apply -> exit function here
  // at this point, player is on ladder
  if (mouse.Mode == eModeWalkto) {
    Display("You'll have to get down from the ladder first.");
    ClaimEvent(); // prevent standard click handling, nothing further will happen
  }
}
Title: Re: How to make character stand still and not move when the screen is clicked
Post by: Volklaw on Wed 16/05/2018 10:16:50
Wow

Thanks everyone for all of your suggestions!
The fact that there are so many different ways to solve problems is something I am really enjoying about this.

I ended up going with Cassiebsg's approach (thank you!)
I set another animation to occur once the climbing animation finished. I had already tried this previously, however; I realise that last time I tried I did not lock the subsequent view (a view with the final frame of the climb ladder animation). Also, thanks Cassie for some of that bool related advice. I really needed that (!NotOnLadder). I will use that method for bools in the future.

Update: I used Khris' click blocking method on a second problem of a similar nature. It works excellently and is very very useful in cutscenes where you don't want the player to be able to skip through dialogue or walk around in the interim.

Thanks again guys