Make character repetedly talking to stop

Started by Alen101, Mon 21/12/2015 21:36:10

Previous topic - Next topic

Alen101

https://www.youtube.com/watch?v=jdOTF_ErXG0&index=27&list=PLymKb1rMLG2ksaBcEdHeyPCntjapFjONxhttps://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!




Cerno

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.
123  Currently working on: Sibun - Shadow of the Septemplicon

Slasher

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.

Alen101

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

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

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
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!.");
          
      }

Slasher

to stop a timer set it to 0 (eg SetTimer(1, 0); ) in the global will stop the timer

Cerno

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
if(IsTimerExpired(1) && IsVentasTalking && !cVentas.HasInventory(iThingy))


If I misunderstood what you want to do, please let me know.
123  Currently working on: Sibun - Shadow of the Septemplicon

Khris

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

Cerno

#7
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:

  • You are right that the cVenta_UseInv has to be handled in GlobalScript and with the fix of setting IsVentasTalking to false it should work.
  • As slasher pointed out, the variable IsVentasTalking should be made global (check the Global Variables section in your project tree), so you don't have to define it in the Room script. Make sure you initialise it to true.
  • As Khris mentioned, putting your if(IsTimerExpired(1) && IsVentasTalking) block in the room's repeatedly_execute will be cleaner. However, it should also work in GlobalScript.asc

Try that and tell us if it works.
123  Currently working on: Sibun - Shadow of the Septemplicon

Alen101

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::)

Alen101

So this is the way i use:
i left it here because maybe it can help others,

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


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



ON REP EXEC:
Code: ags
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.

SMF spam blocked by CleanTalk