Having charX appear and animate only if charY is following the player

Started by SlinkyB, Wed 01/01/2025 21:25:54

Previous topic - Next topic

SlinkyB

I hope this post found its way to the right place (and that there is still any activity on this platform haha)

So I quite recently started messing around with AGS as I was sick and bored to death, so I'm very much a beginner. I however tried to google this question of mine and really tried to go through the manual and old threads here but couldn't find the answer so I hope I don't seem like an idiot ANYWAYS

I would like to write some kind of if/else command where;

If you interact with a specific hotspot, and a certain character is following you, another character will appear and start animating

Otherwise (if the character is not following you), clicking on the hotspot will simply display some text

So everything else is pretty clear to me or at least clear enough to trial-and-error my way through, but I don't understand what to write in the script for the "if" statement. I thought it would be enough to write

If (cChar2.FollowCharacter(cChar3));
{Yada yada}

But that was unsuprisingly not enough:D

I don't know if this made any sense but if someone could help me I'd be very thankful🙏🙏

eri0o

Code: ags
 If (cChar2.FollowCharacter(cChar3));

This should be invalid code but it may be a leftover from old things in ags3 and we definitely should throw an error in there on ags4.

In 3.6.2 beta and forwards we added Character.Following.

https://adventuregamestudio.github.io/ags-manual/Character.html#characterfollowing

Other than this it would be interesting if you could explain more of what you are trying to accomplish.

Crimson Wizard

@eri0o this is a beginner user, who cannot tell why the code is invalid, and likely knows nothing about "ags3" or "ags4". It's worth explaining WHY is the code invalid too.

@SlinkyB,

FollowCharacter function orders one character follow another, but it's not suitable for checking whether it currently follows or not. It will always start following, so all that you will accomplish with this is that whenever this condition runs cChar2 will begin following cChar3. Also, AFAIK it does not have a return value, so the result of checking if "(cChar2.FollowCharacter(...))" will be always false.

Prior to AGS 3.6.2 there's no character's property that would tell that one character follows another. Well, strictly speaking, there is, but it's a part of deprecated API, and is hidden now. You could enable old API, but I would not recommend, as that will also enable lots of other things which are no longer recommended to use.

There are 2 options:

OPTION 1. Upgrade to AGS 3.6.2 Beta, which has Character.Following property (as mentioned by eri0o above). This option may be easier if you're just starting your game. "Following" property is used like this:
Code: ags
if (cChar2.Following == cChar3)
AGS 3.6.2 download may be found here:
https://www.adventuregamestudio.co.uk/forums/ags-engine-editor-releases/ags-3-6-2-beta-1-a-wip-3-6-update/

OPTION 2. If you prefer staying in a previous version, then create a boolean global variable, for example - "char2IsFollowingChar3", and assign it along with calling FollowCharacter (where you do this), like:
Code: ags
cChar2.FollowCharacter(cChar3);
char2IsFollowingChar3 = true;
and when you stop following, like:
Code: ags
cChar2.FollowCharacter(null);
char2IsFollowingChar3 = false;
then check that variable in a your hotspot condition, like:
Code: ags
if (char2IsFollowingChar3)

Global Variables panel is the easiest way to add global variables in AGS for beginners, it may be found in the project explorer.

SlinkyB

Thanks for all the help! Still have a lot to figure out, like how to make the npc invisible first and why can't I get him moving lmao, but those are things I'll just have to work out myself. HOWEVER, those global variables were the solution to my original problem in this post, so thank you @Crimson Wizard !

@eri0o , so what I was trying to accomplish is that your character starts in a bar, and if you interact with the barcounter the player will just say "where's the bartender?". However, if you get this one dart off the dartboard and give it to another character in the bar, that character will suggest you both go looking for the bartender, and will start following you. This far I've made it, and what I was hoping to happen next is that if you'd now interact with the barcounter with the other guy following you, the bartender would show up.

Essentially I'm just messing around though! But like I said, I still have a lot of tweaking to do with the bartender-situation but those global variable thingys seemed to be the help I was looking for! Thank you both for replying!

Joacim Andersson

As Crimson Wizard already said, you might need to create your own variable and toggle its value to see if a character is following another. Even if you download the beta version of 3.6.2 it might be good to remember this since you might need to do completely other things that you must remember the state of.

Another thing for this particular case is depending on the design of your game, Will the character that will follow you even be in this room if it doesn't follow you? If not, then just check the room they're in:
Code: ags
if (otherCharacter.Room == player.Room)

To make a character invisible you can simply set the Transparency property of the character.
Code: ags
someCharacter.Transparency = 100; // Set to 0 to make it visible
Or you can have the character in a different room (or -1 for no room) and simply set it to be in this room when it needs to appear.

SMF spam blocked by CleanTalk