Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: zeta_san on Mon 24/06/2024 08:54:01

Title: [SOLVED]Problem with eGA_GiveTo
Post by: zeta_san on Mon 24/06/2024 08:54:01
Good morning
I ask for your help to understand if it is a bug or I make mistakes.


function cLupo_AnyClick() {
    if (Verbs.MovePlayer(340, 140)) {
        player.FaceDirection(eDirectionRight);
        // WALK TO
        if (Verbs.UsedAction(eGA_WalkTo)) {
            Verbs.GoTo();
        }
        // GIVE TO (characters only)
        else if (Verbs.UsedAction(eGA_GiveTo)) {
            if (player.ActiveInventory == iObject) {
                player.LoseInventory(iObject);
                player.Say("do you want this?");
                cLupo.Say("WOW! YES. I want it");
            } else if (player.ActiveInventory != iObject) {
                player.Say("do you want this?");
                cLupo.Say("No");
            }
        }
    }
}


When I give an object to an NPC for the first time nothing happens, psi approaches and nothing happens. If I repeat the action everything is normal
Title: Re: Problem with eGA_GiveTo
Post by: Khris on Mon 24/06/2024 15:31:11
Try adding Display() commands to see exactly what is happening.

You can also try removing the eGA_WalkTo branch since your moving the player to the character manually anyway.
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Mon 24/06/2024 17:28:51
Quote from: Khris on Mon 24/06/2024 15:31:11Try adding Display() commands to see exactly what is happening.

You can also try removing the eGA_WalkTo branch since your moving the player to the character manually anyway.

The anomaly persists. Display() exactly how I set it?
Title: Re: Problem with eGA_GiveTo
Post by: Khris on Mon 24/06/2024 22:46:48
Like this:

function cLupo_AnyClick() {
    if (Verbs.MovePlayer(340, 140)) {
        Display("Move player finished");
        player.FaceDirection(eDirectionRight);
        // WALK TO
        if (Verbs.UsedAction(eGA_WalkTo)) {
            Display("action is walk");
            Verbs.GoTo();
        }
        // GIVE TO (characters only)
        else if (Verbs.UsedAction(eGA_GiveTo)) {
            Display("action is give");
            if (player.ActiveInventory == iObject) {
                player.LoseInventory(iObject);
                player.Say("do you want this?");
                cLupo.Say("WOW! YES. I want it");
            } else if (player.ActiveInventory != iObject) {
                player.Say("do you want this?");
                cLupo.Say("No");
            }
        }
    }
}
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Tue 25/06/2024 09:38:34
Nothing... it doesn't work, I've made multiple attempts but I can't resolve anything. Do you know if anyone has the same problem as me?
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Tue 25/06/2024 19:56:31
I noticed that if the action happens from left to right nothing happens, if it happens from right to left everything happens fine.
I thought it was the alpha channel of the sprite or the character animation. I can not understand ..
Title: Re: Problem with eGA_GiveTo
Post by: Khris on Tue 25/06/2024 23:55:27
Well, the entire thing depends on
if (Verbs.MovePlayer(340, 140)) {so if that fails, (edited for clarity:) the player walks towards these coordinates but then can't reach them and they stop and nothing happens.

The question is, why does it fail from one side and not the other? And does the function itself have a bug?
Make sure that 340, 140 is part of the walkable area and also not blocked by the NPC's solidity rectangle.
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Wed 26/06/2024 12:55:10
I tried them all.. I think it's a bug
Title: Re: Problem with eGA_GiveTo
Post by: eri0o on Wed 26/06/2024 13:31:52
Show a printscreen of the walkable area with the characters in the room editor and mark where is the 340x140 coordinate and from where the movement is failing.
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Wed 26/06/2024 16:52:50
1) From left to right: It doesn't work

2) From right to left: it works

3) From left to right: Not working again

4) From left to right in that position: it works


Title: Re: Problem with eGA_GiveTo
Post by: Khris on Wed 26/06/2024 20:12:43
Look at 0:07 and compare that to 0:23.
It's very visibly a different position.

I assume 340, 140 is where the player is at 0:23, so the question is why they don't reach that coordinate the first time around.
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Wed 26/06/2024 20:31:22
Quote from: Khris on Wed 26/06/2024 20:12:43Look at 0:07 and compare that to 0:23.
It's very visibly a different position.

I assume 340, 140 is where the player is at 0:23, so the question is why they don't reach that coordinate the first time around.

I can't understand why
I tried to write everything down again

function cLupo_AnyClick() {
  if (Verbs.MovePlayer(340, 140)) {
    player.FaceDirection(eDirectionRight);
    // WALK TO
    if (Verbs.UsedAction(eGA_WalkTo)) {
      Verbs.GoTo();
    }
    // GIVE TO (characters only)
    else if (Verbs.UsedAction(eGA_GiveTo)) {
      player.FaceDirection(eDirectionRight);
      if (player.ActiveInventory == iCalcio) {
        player.LoseInventory(iCalcio);
        player.Say("Vuoi questo poster?");
        cLupo.LockView(175);
        cLupo.Animate(0, 2, eOnce, eBlock, eForwards);
        cLupo.UnlockView();
        cLupo.LockView(103);
        cLupo.Animate(1, 5, eOnce, eBlock, eForwards);

        cLupo.Say("WOW! Il poster di Bruno Conti");
        cLupo.Say("Ti do la moneta");
        player.AddInventory(iCoin);
        moneta = true;
        cLupo.UnlockView();
      } else if (player.ActiveInventory != iCalcio) {
        player.Say("Vuoi questo?");
        cLupo.Say("No. Non lo voglio");
      }
    }
  }
}
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Wed 26/06/2024 20:47:56
I inserted a second PNG and placed it on the left.. it works in reverse
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Fri 04/10/2024 18:03:17
Update:

Hi everyone
I am finding this anomaly in every room.
When I give an object to a player, the first time nothing happens, I have to repeat the operation.
Do you happen to you?

(Turseweed Action Functions)
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Sat 05/10/2024 20:17:23
@Khris

Sorry but I tried all the possible solutions but I have a problem with Giveto.
The first time I launch the command, the player approaches the PNG but nothing happens, everything he is later

If (Verbs.usedation (Ega_giveto)) {

it is ignored

When I repeat the command, it works

I don't understand what blocks it, is there a link for assistance?

I also tried with

Player.walk (CNET.X - 20, Cnet.y, Eblock, Ewalkableareas);
To get him closer but nothing
Title: Re: Problem with eGA_GiveTo
Post by: pell on Sat 05/10/2024 20:50:09
My understanding is that the transparent parts of images still count in the collision detection. I had an issue with that in a game a few years ago. In the video it looks like the character might be getting blocked by part of the fishing hole image.

If you have extra space around the image, you may try trimming it down to only surround the visible parts. If the girl and the fishing hole are all part of one image, you might break them into separate images so that the rectangle surrounding the different parts can fit more closely.

You could also try having the character first walk to a spot from where you know he can always reach the correct spot to trigger the dialog.
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Sat 05/10/2024 21:12:34
The problem is that everything I write after
If (Verbs.usedation (Ega_giveto)) {
The first time is ignored

example

If (Verbs.usedation (Ega_giveto)) {
Player.say ("Hello");

It does nothing, it goes directly close to the PNG
only when I repeat the action everything works
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Sun 06/10/2024 21:30:39
All actions work at the first call but Giveto only works at the second.
I'm going crazy I tried them all.
What can be the reason .. AGS?
Title: Re: Problem with eGA_GiveTo
Post by: Khris on Mon 07/10/2024 09:16:18
Once again, you need to put Display commands in your code to try and debug this.
Does the function trigger at all? Where exactly does AGS exit the function?

Edit:
I just checked my AGS 3.6 Tumbleweed example game and the "give to" action works without issue, same as the other verbs.
To debug this, we need to determine which of the two if conditions fails. I suspect it's the move part again, but if the other verbs do work, then it must be something else.

If you upload your source code and send me a link I will take a look.
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Mon 07/10/2024 09:25:44
Quote from: Khris on Mon 07/10/2024 09:16:18Once again, you need to put Display commands in your code to try and debug this.
Does the function trigger at all?

Sorry if I insist with this thing ..
I also tried this but as I said, after the first call "give" does not perform any action, it approaches the PNG and nothing happens.
Any code I write after

If (Verbs.usedation (Ega_giveto)) {
is ignored
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Mon 07/10/2024 10:16:12
function room_AfterFadeIn() {
Display ("Start of the test");

if (Verbs.UsedAction(eGA_GiveTo)) {
Display ("Give_to recognized action!");

 // Here the code to be performed
} else {
Display ("Give_to unrecognized action!");
}

 Display ("Completed test");
}



Give_to unrecognized action!
Title: Re: Problem with eGA_GiveTo
Post by: Khris on Mon 07/10/2024 10:19:34
This will never trigger. That function runs once after the room has faded in, but at that point Verbs.UsedAction(eGA_GiveTo) will never be true.

You need to actually click the give button, an inventory item and a character to properly test this (or simulate the action some other way, provided the template supports that).

(Also, this is why it is so important to always post your actual code. Testing it this way won't work, so getting stuck on this not working is a complete waste of time.)
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Mon 07/10/2024 10:46:03


function cNet_AnyClick(Character *theCharacter, CursorMode mode)
{

    // WALK TO
    if (Verbs.UsedAction(eGA_WalkTo)) {
        Verbs.GoTo();
    }

    // Check if the action used is GIVE TO
    else if (Verbs.UsedAction(eGA_GiveTo)) {

        // Move the player towards cNet's position and wait for the movement to finish
        player.Walk(cNet.x - 20, cNet.y, eBlock, eWalkableAreas);  // Walk close to cNet, 20 pixels away
        player.FaceCharacter(cNet);  // The player looks at cNet
       
        player.Say("Hey, do you want this?");

        // If I give him the soap
        if (Verbs.GetItemGiven() == iSoap) {
            player.LoseInventory(iSoap);
            player.Say("Will this do?");
           
            // cNet's dialogue
            cNet.Say("For all surfaces, for stubborn dirt");
            cNet.Say("Muriatic acid");
            cNet.Say("Pure bleach");
            cNet.Say("Depleted uranium");
            cNet.Say("Emotoxin rattlesnake venom");
            cNet.Say("Strychnine");
            cNet.Say("Formaldehyde");
            cNet.Say("Palm oil");
            cNet.Say("WOW!");
            cNet.Say("PERFECT!");

            // Mark that you have given the soap
            hodatosapone = true;
        }   
        // If I have already given him the soap
        else if (hodatosapone == true) {
            player.Say("I've already given him the soap.");
        }
        // If I give him something else
        if (Verbs.GetItemGiven() != iSoap) {
            player.Say("I don't think he's interested.");
        }
    } else {
        Verbs.Unhandled();
    }
}


Title: Re: Problem with eGA_GiveTo
Post by: Khris on Tue 08/10/2024 06:37:30
Try this:

function cNet_AnyClick(Character *theCharacter, CursorMode mode) {
  // approach character non-blocking
  if (Verbs.MovePlayer(cNet.x - 20, cNet.y)) {
    player.FaceCharacter(cNet, eBlock);
    // Check if the action used is GIVE TO
    if (Verbs.UsedAction(eGA_GiveTo)) {
      player.Say("Hey, do you want this?");

      // If I give him the soap
      if (Verbs.GetItemGiven() == iSoap) {
        // if NPC didn't receive soap yet
        if (!hodatosapone) {
          player.LoseInventory(iSoap);
          player.Say("Will this do?");

          // cNet's dialogue
          cNet.Say("For all surfaces, for stubborn dirt");
          cNet.Say("Muriatic acid");
          cNet.Say("Pure bleach");
          cNet.Say("Depleted uranium");
          cNet.Say("Emotoxin rattlesnake venom");
          cNet.Say("Strychnine");
          cNet.Say("Formaldehyde");
          cNet.Say("Palm oil");
          cNet.Say("WOW!");
          cNet.Say("PERFECT!");

          // Mark that you have given the soap
          hodatosapone = true;
        }   
        // If I have already given him the soap
        else {
        player.Say("I've already given him the soap.");
        }
      }
      // If I give him something else
      else {
        player.Say("I don't think he's interested.");
      }
    } else {
      Verbs.Unhandled();
    }
  }
}

It's a design choice whether the player character always approaches first or not, but this is the way all the LucasArts 9-Verb games did if, IIRC.

Anyway, you said only "give" didn't work, but this code has a blocking walk inside the handling of "give" (which is not really how the template is supposed to work) and I have no idea if that code is the one that caused the original trouble.

I fixed it in the way that I think works best with the template, and I also fixed the soap logic (you didn't check the hodatosapone variable first, so if the player can pick up more soap, they can keep giving it to cNet).
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Tue 08/10/2024 14:58:41

Title: Re: Problem with eGA_GiveTo
Post by: Khris on Tue 08/10/2024 15:36:14
1. is this your code or my code?
2. he makes an additional step when you click a second time, meaning that the character doesn't reach the target the first time around, which is most likely the reason the code doesn't trigger

Assuming this is my code, what happened when you ran your code with the blocking walk?

Also, feel free to PM me a link to the game so I can take a look. I have a sneaking suspicion that I can easily fix this if I have the source code.
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Tue 08/10/2024 21:35:16
Quote from: Khris on Tue 08/10/2024 15:36:14Also, feel free to PM

Done
Title: Re: Problem with eGA_GiveTo
Post by: Khris on Wed 09/10/2024 18:06:21
Found it, and I remember having found this before.

Open TemplateSettings.asc and find line 66:

  // walk to character before starting interaction
  Verbs.VerbGuiOptions[eVerbGuiApproachCharInteract] = false;

This option needs to be set to false, otherwise the template takes over the Give click and does not run the interaction function if the character fails to reach an automatically calculated target.

Edit: found the other topic; the error was just as frustrating; maybe the template should default to this being turned off
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/character-walks-into-npc-when-talking/msg636513014/#msg636513014
Title: Re: Problem with eGA_GiveTo
Post by: Crimson Wizard on Wed 09/10/2024 18:14:39
Quote from: Khris on Wed 09/10/2024 18:06:21Edit: found the other topic; the error was just as frustrating; maybe the template should default to this being turned off

Note you may add your suggestion in the template's issue tracker here:
https://github.com/dkrey/ags_tumbleweed/issues
Title: Re: Problem with eGA_GiveTo
Post by: zeta_san on Wed 09/10/2024 21:40:43
@Khris Thank you, you solved a huge problem for me... now I can move forward. Thank you!