Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: lafouine88 on Fri 09/02/2024 11:17:21

Title: [SOLVED]identifying characters "^^?
Post by: lafouine88 on Fri 09/02/2024 11:17:21
Hey guys

I would like to create a targeting function, like when I left click on the character (on any map) he gets selected (and thus appropriate lifebars etc. can appear). Sounds easy, yet I can't find the right way.

I came up with something like that ('Target' is a Character GlobalVar to identify the right character), it sounded promising.
function on_mouse_click(MouseButton button)
{

    if(button==eMouseLeft){
     
            if (GetLocationType(mouse.x, mouse.y) == eLocationCharacter)
      {
        Room.ProcessClick(mouse.x,mouse.y, eModeLookat);//----------and in character1.lookAt it goes "Target=Character1"
       LblEnnemyname.Text=String.Format("%s", ennemis[Target.ID-3].Nameennemy);//---so the lifebar displays the right name of the target contained in the struct 'ennemis'

      }
//...

but this does'nt work, for some reason the function seems to skip the 'room.process' which creates the Target variable, and goes straight to the next lines (which creates a problem because the target is'nt identified)

Any ideas? I can be more specific if needed.
Thanks a lot :)

EDIT : Writing it gave me the answer, I just needed to put the function in the lookat section rather than in the global script, this way it doesn't skip the interaction and it works fine now :)
Title: Re: [SOLVED]identifying characters "^^?
Post by: Rik_Vargard on Sat 10/02/2024 23:43:27
Can't you use something like this?
When you click on the character (or an image representing the character):
c[CharacterName].SetAsPlayer;
Title: Re: [SOLVED]identifying characters "^^?
Post by: Khris on Sun 11/02/2024 12:32:14
You don't to need use the lookat event. You can call Character.GetAtScreenXY(mouse.x, mouse.y) to find the clicked character and simply set your pointer variable directly.

Title: Re: [SOLVED]identifying characters "^^?
Post by: lafouine88 on Sun 11/02/2024 21:53:38
Thanks Kris, it's much easier like that :)