Author Topic: How to make character stand still and not move when the screen is clicked  (Read 261 times)

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;

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Okay, first thing is to get the [ code ] tag in there so we can see the code properly.

Code: Adventure Game Studio
  1. //Climbing ladder animation
  2. function oLadderUsed_Interact()
  3. {
  4.     if (NotOnLadder) {
  5.         cEgo.Walk(251, 378, eBlock); // cEgo is walking to the coordinates where the animation (climbing) will begin[/color]
  6.         cEgo.LockView(3);
  7.         cEgo.Animate(0, 1, 0, eBlock, eForwards);
  8.         RemoveWalkableArea(1); // this is only needed if walkable area 1 reaches the chords where your character is now.
  9.         NotOnLadder = false;
  10.         OnLadder = true;
  11.         }
  12.     else
  13.     {
  14.         cEgo.LockView(3);                    // Process of animation is reversed
  15.         cEgo.Animate(0, 1, 0, eBlock, eBackwards);
  16.         RestoreWalkableArea(1);
  17.         cEgo.UnlockView(3);
  18.         NotOnLadder = true;
  19.         OnLadder = false;
  20. } // ] <-- 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.

Code: Adventure Game Studio
  1. //Climbing ladder animation
  2. function oLadderUsed_Interact()
  3. {
  4.     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.
  5.         cEgo.Walk(251, 378, eBlock);         // cEgo is walking to the coordinates where the animation (climbing) will begin
  6.         cEgo.LockView(3);
  7.         cEgo.Animate(0, 1, 0, eBlock, eForwards);
  8.         RemoveWalkableArea(1);               // cEgo is now at top of ladder
  9.         NotOnLadder = false; // good.
  10.         // OnLadder = true; (this is not needed)
  11.         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).
  12.  
  13.         }
  14.     else // this means that you are on top of the ladder
  15.     {
  16.         cEgo.LockView(3);                    // Process of animation is reversed
  17.         cEgo.Animate(0, 1, 0, eBlock, eBackwards);
  18.         RestoreWalkableArea(1);
  19.         cEgo.UnlockView(3);
  20.         NotOnLadder = true;
  21.     }
  22. }
  23.  

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.
« Last Edit: 14 May 2018, 14:29 by Cassiebsg »
There are those who believe that life here began out there...

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
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 :

Code: Adventure Game Studio
  1.  
  2. bool isOnTopOfLadder = false;
  3.  
  4. void blockWalking()
  5. {
  6.    if (player.Room == /* the room where it's supposed to blok */)
  7.    {
  8.        isOntopOfLadder = /* conditions to return true if he's supposed to be on top of ladder */;
  9.  
  10.        if(isOnTopOfLadder)
  11.        {
  12.            if(player.Moving)
  13.            {
  14.                player.StopMoving();
  15.            }
  16.  
  17.            //Do this only if needed
  18.            player.LockView(/* the view wheree stands still at the top of te ladder */);
  19.        }
  20.     }
  21. }
  22.  
  23. //block the walk at the beginning of the game loop
  24. void repeatedly_execute_always()
  25. {
  26.     blockWalking();
  27. }
  28.  
  29. //block the walk at the end of the game loop too (just in case)
  30. void late_repeatedly_execute()
  31. {
  32.     blockWalking();
  33. }
  34.  
  35.  
  36.  
 

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
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:
Code: Adventure Game Studio
  1. function on_mouse_click(MouseButton button) {
  2.   if (!OnLadder) return; // not on ladder, standard rules apply -> exit function here
  3.   // at this point, player is on ladder
  4.   if (mouse.Mode == eModeWalkto) {
  5.     Display("You'll have to get down from the ladder first.");
  6.     ClaimEvent(); // prevent standard click handling, nothing further will happen
  7.   }
  8. }

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
« Last Edit: 18 May 2018, 13:49 by Volklaw »