[SOLVED]identifying characters "^^?

Started by lafouine88, Fri 09/02/2024 11:17:21

Previous topic - Next topic

lafouine88

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.
Code: ags
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 :)

Rik_Vargard

Can't you use something like this?
When you click on the character (or an image representing the character):
c[CharacterName].SetAsPlayer;

Khris

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.


lafouine88

Thanks Kris, it's much easier like that :)

SMF spam blocked by CleanTalk