Making non blocking Talking

Started by joelphilippage, Sun 13/01/2008 01:55:20

Previous topic - Next topic

joelphilippage

I am trying to make a command to make the character say things non-blocking and animate the talking view when the character is standing still. This is the script I have.
Function:
Code: ags

function Nonblocksay(String message){
  cEgo.SayBackground(message);
  SetGlobalInt(200, 1);
}

here I made a function that will have the character say something non-blocking then set the global int 200 to 1.
Repeatedly Execute:
Code: ags

function repeatedly_execute() 
{
  if(GetGlobalInt(200)==1){
      if(cEgo.Moving == false){
      cEgo.LockView(cEgo.SpeechView);
  cEgo.Animate(cEgo.Loop, 4, eRepeat, eNoBlock);
}
else{
  cEgo.UnlockView();
    }
    if(cEgo.Speaking == false){
     cEgo.UnlockView();
      SetGlobalInt(200, 0);
}
}
}

Here I made it so if the global int 200 is set to one, the main character will talk when standing still.
The main character says the message non-blocking, but for some reason he will not talk when standing still.
Does anyone know why?



Gilbert

From the manual, in the "Character.Speaking" part:
QuoteIt will only return true for the active talking character; that is, it will not return true for any characters talking with the SayBackground command.

So your way to check whether the character is speaking just won't work.

So, instead, use an overlay pointer to check whether the speech text is still on screen. Something like (untested):
Code: ags

Overlay* egospeaking;
function Nonblocksay(String message){
  egospeaking = cEgo.SayBackground(message);
  SetGlobalInt(200, 1);
}

Code: ags

function repeatedly_execute() 
{
  if(GetGlobalInt(200)==1){
      if(cEgo.Moving == false){
      cEgo.LockView(cEgo.SpeechView);
  cEgo.Animate(cEgo.Loop, 4, eRepeat, eNoBlock);
}
else{
  cEgo.UnlockView();
    }
    if(egospeaking == Null){
     cEgo.UnlockView();
      SetGlobalInt(200, 0);
}
}
}



joelphilippage

That seems to work better however, it only shows the first frame of the animation when the character is walking or talking. Is there a way I could fix this?



Gilbert

Hmmm, try this, as the current code might continuously reset the animation as it'll call LockView() and Animate() once every game loop:

Code: ags

Overlay* egospeaking;
function Nonblocksay(String message) {
  egospeaking = cEgo.SayBackground(message);
  SetGlobalInt(200, 1);
}

Code: ags

function repeatedly_execute() {
  if(GetGlobalInt(200)==1) {
      if (cEgo.Moving == false) {
        if (cEgo.View!=cEgo.SpeechView)){
          cEgo.LockView(cEgo.SpeechView);
          cEgo.Animate(cEgo.Loop, 4, eRepeat, eNoBlock);
        }
      } else cEgo.UnlockView();
  }
  if (egospeaking == Null) {
     cEgo.UnlockView();
     SetGlobalInt(200, 0);
  }
}


This might not fix the walking part yet (I'm not sure).

joelphilippage

Ok I tried out your code and changed a few things because he still couldn't walk. Now for some reason he won't stop animating the talk animation when standing still after he is done talking.
Code: ags

Overlay* egospeaking;
function Nonblocksay(String message) {
  egospeaking = cEgo.SayBackground(message);
  SetGlobalInt(200, 1);
}

Code: ags

function repeatedly_execute() {
  if(GetGlobalInt(200)==1) {
      if (cEgo.Moving == false) {
        if (cEgo.View!=cEgo.SpeechView){
          cEgo.ChangeView(cEgo.SpeechView);
          cEgo.Animate(cEgo.Loop, 4, eRepeat, eNoBlock);
        }
      } 
      else{
        if(cEgo.View!=1){
        cEgo.ChangeView(1);
      }
      }
  if (egospeaking == null) {
     if(cEgo.View!=1){
     cEgo.ChangeView(1);
     SetGlobalInt(200, 0);
     }
}
}
}



Gilbert

Hmmm, I think I made some small mistake here, turned out when an overlay is once initialised, removing it will not turn it back to null, just that the Valid property is changed to 0.

Try changing the line:
  if (egospeaking == null) {

to:
  if (egospeaking != null) if (egospeaking.Valid==0) {

joelphilippage

Thanks. It works perfectly now.



SMF spam blocked by CleanTalk