[SOLVED]Problem with eGA_GiveTo

Started by zeta_san, Mon 24/06/2024 08:54:01

Previous topic - Next topic

zeta_san

Code: ags
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!

Khris

#21
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.)

zeta_san



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();
    }
}



Khris

Try this:

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


Khris

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.


Khris

#27
Found it, and I remember having found this before.

Open TemplateSettings.asc and find line 66:

Code: ags
  // 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

Crimson Wizard

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

zeta_san

@Khris Thank you, you solved a huge problem for me... now I can move forward. Thank you!

SMF spam blocked by CleanTalk