Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Imhotep on Sun 30/07/2006 12:41:31

Title: Scripting help for FollowCharacter
Post by: Imhotep on Sun 30/07/2006 12:41:31
I have used

Ã,  Ã, cShoe.FollowCharacter(cEgo,FOLLOW_EXACTLY,0);

and it works. And cEgo is animated at walking like it's view. But cShoe is only a static sprite, which I like to be animated by walking too.

Thankyou and Greetings from Germany
Title: Re: Scripting help for FollowCharacter
Post by: Khris on Sun 30/07/2006 12:59:23
Did you set up proper walk cycle frames in cShoe's Normal view?
What happens if you make cShoe the player character and walk around?

(Kennst Du daujones.com?)
Title: Re: Scripting help for FollowCharacter
Post by: limeTree on Sun 30/07/2006 14:55:37
When Shoe walks normaly,does it move as a static sprite,or it has a complete animation?
Title: Re: Scripting help for FollowCharacter
Post by: Imhotep on Sun 30/07/2006 22:12:29
Yes, cShoe has cycle frames for 8 directions like cEgo has. And it is compledly animated, when walk around as the player character. It is also animated, when

   cShoe.FollowCharacter(cEgo,10,10);

is used.

(@KhrisMUC: Hab grad mal geschaut, LOL)
Title: Re: Scripting help for FollowCharacter
Post by: Khris on Sun 30/07/2006 22:28:14
That's weird. I've never used FollowCharacter with the FOLLOW_EXACTLY option, but there's a workaround using repeatedly_execute to make sure Character.X, Character.Y and so on stay the same for both characters.

(Es gibt einen Imho-tep bei daujones, deswegen hab ich gefragt :))
Title: Re: Scripting help for FollowCharacter
Post by: GarageGothic on Mon 31/07/2006 01:46:14
if setting the X and Y coordinates in the repeatedly_execute, make sure to also set the followcharacter's loop and frame accordingly, since he won't animate by himself.
Title: Re: Scripting help for FollowCharacter
Post by: Imhotep on Mon 31/07/2006 08:02:56
Well if using

   cShoe.x=cEgo.x;
   cShoe.y=cEgo.y;

in RepEx it's not better. cShoe even begins to flicker. And I'm not sure how to animate it, because it should use its walk-cycle-frames and not a specified loop of a view like cShoe.Animate will do.
Title: Re: Scripting help for FollowCharacter
Post by: Alynn on Mon 31/07/2006 08:28:15
Crazy random thought... is cEgo block moving? I've never played with the follow character, but it would make sense that while it may still follow, it may not animate if ego is blocking...

Like I said random thought, never used follow char, so I may be completely wrong.
Title: Re: Scripting help for FollowCharacter
Post by: Imhotep on Mon 31/07/2006 08:57:59
That was a good idea to explain, but I don't think that cEgo is blocking because it is player character. And if cShoe follows it with distance both are animated like they should.
Title: Re: Scripting help for FollowCharacter
Post by: Imhotep on Thu 03/08/2006 07:38:13
Hmm, I thought it would be easier to solve this problem. I'm trying around but it's not working...

Noboby with experience in this?
Title: Re: Scripting help for FollowCharacter
Post by: Gilbert on Thu 03/08/2006 08:01:53
Well, two questions here:
1. Where did you put the FollowCharacter() line ? Make sure that you only need to call it once and then the character will follow the player and animated as instructed until the function is called again. If you call it repeatedly (like in repeated_execute() say for example) it may happen that each time the function is called the character got reset so the sprite looks like it's static.
2. If you used the modify x, y- coordinates method, make sure you DON'T do it together with FollowCharacter(), since modifying the coordinates while a character is moving (using FollowCharacter() makes him move) is not recommended and can cause problems.


My suggestion is, try using the FollowCharacter() method first, and like in 1. mentioned, make sure that the function is called only once (like putting it in "player enters room" say for example) and it's not called repeatedly. Normally, you don't need to manually mess with his coordinates unless you want to do more advanced stuff.
Title: Re: Scripting help for FollowCharacter
Post by: Imhotep on Thu 03/08/2006 09:13:14
I put it here:

    // script for Room: Player enters room (after fadein)
   cShoe.FollowCharacter(cEgo,FOLLOW_EXACTLY,0);

Have I to add another command for the animation?
Title: Re: Scripting help for FollowCharacter
Post by: Gilbert on Thu 03/08/2006 09:46:17
Well I'd checked it, and indeed got your problem.
It's a know issue (http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=574) actually.

A workaround is to add this to the script (if you had already created a repeatedly_execute_always() function, just copy the 2 lines of codes):

function repeatedly_execute_always(){
  cShoe.Loop=cEgo.Loop;
  cShoe.Frame=cEgo.Frame;
}


However, this is not perfect, seems that there's still a 1 frame lag on the cShoe frame, just sort of working.
Title: Re: Scripting help for FollowCharacter
Post by: Imhotep on Thu 03/08/2006 10:03:29
Hurray, that's the way I wanted it! Okay the lag is still there, but maybe the FollowCharacter() will be fixed in future.

Thanks to all of you.
Title: Re: Scripting help for FollowCharacter
Post by: gypsysnail on Mon 09/10/2006 12:49:01
Hi I know this thread was from a little while back but I am also going to have a small character follow my character for the most part of the game. I just wonder what happens - that I have my main character having 7 total frames for her walk in every direction and the small follow character having only 2 frames - is this ok? If not, what must I do? Help much appreciated for this newbie :).
Title: Re: Scripting help for FollowCharacter
Post by: SSH on Mon 09/10/2006 13:52:56
Well, most of this thread is irrelevant if you want to just have one character follow another around. The stuff discussed here is if you want to do something complicated like use a character for a shadow which must animate exactly the same as the main character. Your thing needn't worry about all this, just run FollowCharacter and forget about it!
Title: Re: Scripting help for FollowCharacter
Post by: gypsysnail on Thu 12/10/2006 03:14:58
Ok that is easy. The problem is also, how can I edit the script to have the bird sit on the character's shoulder whenever the player stops the character's walk any time? If someone knows how to tweak this, that would be great!
Title: Re: Scripting help for FollowCharacter
Post by: SSH on Thu 12/10/2006 09:45:47
Good question and not simple. But here goes:

First, you need to detect when the player is moving, so you'll need to check player.Moving in the repeatedly_execute. Then you need to make the bird move non-Blocking to the correct position for the shoulder of the player character. You may also need to make sure that the baseline of the bird is set to more than the baseline of the player (cBird.Baseline=player.Baseline+1 in rep_ex)

Title: Re: Scripting help for FollowCharacter
Post by: gypsysnail on Sat 14/10/2006 18:28:11
Hi SSH, thanks for the advice. I have tried, but I think I need further help as I am so new to this kind of scripting, I have tried to put the stop moving script in following the manuals help but I just don't understand the rules of the programming language (just yet) and I tried putting it in and going to test game but got the error that there was a problem in that line where I put the stop moving in. I put it under the repeatedly execute follow character part. If one of you can help me with the stop moving one so bird can sit on the characters shoulder, that would be great. I do understand the baseline somewhat, but its all a bit hazy to me at this point.
Title: Re: Scripting help for FollowCharacter
Post by: Khris on Sat 14/10/2006 18:33:58
1. Always post the exact error something, not "it said smth like" or "there was an error". AGS tells exactly what's bothering it most of the time. Make use of it.

2. Show us the code you use, there's not much we can do without it apart from guessing what went wrong.
Title: Re: Scripting help for FollowCharacter
Post by: gypsysnail on Sat 14/10/2006 18:45:29
The error message was:
There was an error compiling your script. The problem was in: 'Global Script' Error (line 16): parse error: unexpected if

(and from my understanding, I think I have done it all wrong with the 'if')

ok here is my script - it might seem a silly addition by me but you know me being new so be patient pleaseÃ,  ;)

#sectionstart repeatedly_executeÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
Ã,  // put anything you want to happen every game cycle here
}
function repeatedly_execute_always(){cJonah.FollowCharacter(cEgo, 5, 15);
}
if (character[EGO].x > 299) {
Ã,  character[JONAH].StopMoving();
}
#sectionend repeatedly_executeÃ,  // DO NOT EDIT OR REMOVE THIS LINE
Title: Re: Scripting help for FollowCharacter
Post by: Khris on Sat 14/10/2006 19:05:46
The if-statement isn't inside the function:

function repeatedly_execute_always() {
  cJonah.FollowCharacter(cEgo, 5, 15);
  if (character[EGO].x > 299) {
    character[JONAH].StopMoving();
  }
}


(You don't need to put character[JONAH].StopMoving(); in {}s, that's only needed for grouping commands together. And you can write cJonah instead of character[JONAH].
Title: Re: Scripting help for FollowCharacter
Post by: gypsysnail on Sat 14/10/2006 19:11:27
Ok thanks Khris. Now the problem is the bird stops at co-ordinate >299 (300) - not what I wanted, I got the script from the manual to test to see what would happen. Now I need to take the next step to making the bird stop and sit on my character's shoulder whenever she stops. I have only one frame of the bird sitting - how will I put this into use through the script? Many thanks for the help
Title: Re: Scripting help for FollowCharacter
Post by: on Tue 03/06/2008 16:39:51
About this command, I'm using the new code but after clicking something I want the following character to STOP following the main character. I just can't for the life of me figure it out. The manual says to pass it as "null"...what does that mean? I put null in the chartofollow, eagerness and the other one but the sheep is still following!

How do I stop them from following please? :)
Title: Re: Scripting help for FollowCharacter
Post by: Khris on Tue 03/06/2008 16:51:10
cFollower.FollowCharacter(null);
Title: Re: Scripting help for FollowCharacter
Post by: on Tue 03/06/2008 17:07:14
Great, cheers!! :)
Title: Re: Scripting help for FollowCharacter
Post by: Dualnames on Wed 04/06/2008 13:48:47
The stupid question but whatever does follow function work globally? Which means does the character(follower) change room when the character does? I think he doesn;t but I'm not sure since of the big way big mind boggingly big size of script in my game.
Title: Re: Scripting help for FollowCharacter
Post by: Khris on Wed 04/06/2008 15:45:57
What does the size of your script have to do with anything...?
The following character does follow through all the rooms; he starts out at the coordinates the player entered the room at. And with a short delay, too, depending on the command's parameters.
Title: Re: Scripting help for FollowCharacter
Post by: Dualnames on Wed 04/06/2008 16:11:28
It has. It has. So thanks a lot Khris. Valuable info.