Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Alen101 on Mon 21/12/2015 21:36:10

Title: Make character repetedly talking to stop
Post by: Alen101 on Mon 21/12/2015 21:36:10
https://www.youtube.com/watch?v=jdOTF_ErXG0&index=27&list=PLymKb1rMLG2ksaBcEdHeyPCntjapFjONx (https://www.youtube.com/watch?v=jdOTF_ErXG0&index=27&list=PLymKb1rMLG2ksaBcEdHeyPCntjapFjONx)https://www.youtube.com/watch?v=jdOTF_ErXG0&index=27&list=PLymKb1rMLG2ksaBcEdHeyPCntjapFjONx

So i got a guy talking continously like in the tutorial from above.
He says 3 diferent lines randomly.
Thats pretty cool, but i need him to shut after the player gives him an item.

So i thougth i could resolve it, but i could not.
Because in the example it wont go to global script,
but in my case as its a character it takes me to global script.
Then i dont know where to put the int, and i cant manage to move on.
Any help would be great!



Title: Re: Make character repetedly talking to stop
Post by: Cerno on Mon 21/12/2015 22:01:19
Have you tried using Character.HasInventory(InventoryItem *item) to check whether he has the item?
If yes, let him continue talking. If not, do nothing.
Title: Re: Make character repetedly talking to stop
Post by: Slasher on Mon 21/12/2015 22:05:32
The variable int needs to be global so you can use it anywhere,

You can make it in the global variables pane in the editor.
Title: Re: Make character repetedly talking to stop
Post by: Alen101 on Tue 22/12/2015 01:35:31
Quote from: Cerno on Mon 21/12/2015 22:01:19
Have you tried using Character.HasInventory(InventoryItem *item) to check whether he has the item?
If yes, let him continue talking. If not, do nothing.

Could you explain me a little more?
Rigth now i have this but i have a mess in my head:

I have tryed what you both sayed to me but in the case of slasher:
i cant script all in the global because global havent got repetedly execute (at least ive tryed to use it but wont work)
and i cant script all in the room because i have a character and his scripting take me to global


using Character.HasInventory(InventoryItem *item) to check whether he has the item?
If yes, let him continue talking. If not, do nothing.
This seems to be a good idea but i cant manage to implement it.

i dont know how to make the timer to shut off or to make the char do nothing :(


So i have this:

iVentas (item)
cVenta(character who is talking)
//////////////////////////////////////////////////////



in room script:
Code (ags) Select

int i;
bool IsVentasTalking = true; // line from the tutorial


////////////////////////////////////////////////////////////////////////

In the global script:  (here i cant put this in the room script,
because it needs to be in the global bacause is a character)



Code (ags) Select

function cVenta_UseInv()
{
  if(player.ActiveInventory == iVentas)
  {
  player.Walk(334, 128, eBlock, eWalkableAreas);
  player.FaceLocation(330, 6, eBlock);
player.LoseInventory(iVentas);
cVenta.Say("Gracias.");

IsVentasTalking = true; // line from the tutorial

}

}

/////////////////////////////////////////////////////////////////
back to  room script:

Code (ags) Select
if(IsTimerExpired(1) && IsVentasTalking)// line from the tutorial
       {
          i = Random(2);
          if (i == 0) cVenta.SayBackground("Pssssst.");
          else if (i == 1) cVenta.SayBackground("Pssssssssssst!.");
          else  cVenta.SayBackground("Hey!.");
         
      }
Title: Re: Make character repetedly talking to stop
Post by: Slasher on Tue 22/12/2015 05:35:27
to stop a timer set it to 0 (eg SetTimer(1, 0); ) in the global will stop the timer
Title: Re: Make character repetedly talking to stop
Post by: Cerno on Tue 22/12/2015 06:57:20
Okay, first of all, repeatedly_execute should definitely be available in GlobalScript. So if there isn't a good reason to keep that character talking logic in the room script I would suggest moving it to GlobalScript. Please try again and show your code, maybe we can find out what's wrong.

Second, if you want cVentas to stop talking when he has a certain item, you can add this to your if clause below:

Code (ags) Select
if(IsTimerExpired(1) && IsVentasTalking && !cVentas.HasInventory(iThingy))

If I misunderstood what you want to do, please let me know.
Title: Re: Make character repetedly talking to stop
Post by: Khris on Tue 22/12/2015 10:41:58
Characters are global entities, but that doesn't mean all their code needs to go into the global script. On the contrary, since you can access them in room scripts, why not use the room's RepExec here? That way you don't have to check for player.Room first, and it's tidier to boot.

Also, I recommend getting indentation right from the start.
function cVenta_UseInv()
{
  if(player.ActiveInventory == iVentas)
  {
    player.Walk(334, 128, eBlock, eWalkableAreas);
    player.FaceLocation(330, 6, eBlock);
    player.LoseInventory(iVentas);
    cVenta.Say("Gracias.");
     
    IsVentasTalking = false; // cVenta needs to shut up, so set it to false
  }
}

See how the code is suddenly no longer a huge mess?
Title: Re: Make character repetedly talking to stop
Post by: Cerno on Tue 22/12/2015 19:38:46
Yes, disregard my earlier comment, it was poorly thought out.
Since you already have a variable that controls whether Venta is talking or not, using the HasInventory in addition to that will probably be unnecessarily complicated.

Also to highlight one thing about Khris's post:
In your original code, you set IsVentasTalking to true when you give him the item.
Instead Khris set it to false, which seems to me closer to what you described earlier.
Was that possibly the source of your problem?

To sum it up:

Try that and tell us if it works.
Title: Re: Make character repetedly talking to stop
Post by: Alen101 on Thu 24/12/2015 06:33:54
Thank you Cerno, Slasher and Khris for your help, people in this forum have helped me so much with my game i cannot say enough thanks.
I somehow solved it, but its 3 am and i have no more energy to try to understand exactly how, so tomorrow or in a few days i will post the resolution.
:smiley::):smiley::):smiley::)
Title: Re: Make character repetedly talking to stop
Post by: Alen101 on Sat 02/01/2016 23:26:07
So this is the way i use:
i left it here because maybe it can help others,

out of any function:
Code (ags) Select
bool IsVentasNotTalking = true;

ON LOAD:
Code (ags) Select
SetTimer(1, 120);


ON REP EXEC:
Code (ags) Select
if(IsTimerExpired(1) && IsVentasNotTalking && player.HasInventory(iVentas))
          {
          i = Random(2);
          if (i == 0) cVenta.SayBackground("Pssssst.");
          else if (i == 1) cVenta.SayBackground("Pssssssssssst!.");
          else  cVenta.SayBackground("Hey!.");
          IsVentasNotTalking = true;
          SetTimer(1, 120);
          }


So to shut the character i give him an item.