Scripting issues: SayBackground only works sometimes

Started by itsnotwhatyouthink, Mon 24/09/2012 15:51:44

Previous topic - Next topic

itsnotwhatyouthink

Hi guys, I have run into a problem with the SayBackground command, I'm a complete beginner at scripting, so please pardon my french...

In one room there are three characters that I've moved off screen, when the player speaks to a specific inventory item it triggers a nonsense conversation where the script is blocked. Now, after the conversation is over I would like them to keep talking while the player goes about his/her business in the room... Using the sayBackround command makes it so they all speak at the same time and only the last line, I tried the module from SSH, but keep getting error messages when I try to run the game with it installed (it doesn't seem to recognize half of the variables), I've also tried to use timers, where I call a function in repeatedly execute to make sure the conversation is over, and then IsTimerExpired and so on....The thing is, sometimes it works (typically with short sentences... like, three words) and sometimes it freezes up and the text in the saybackground won't leave the screen. I don't know what to do.

The code is written in a very ineffeicient manner, and I have it in two places, the conversation is in the global script like so:

Code: AGS


function iAstonishingBlast_Talk()
{
  if (cEgo.Room == 37 && (Game.DoOnceOnly("jibberish")))
{
   gWhiteout.Visible = true;
   Wait(4);
   gWhiteout.Visible = false;
   Wait(4);
   gWhiteout.Visible = true;
   Wait(4);
   gWhiteout.Visible = false;

 Display("The voices keep talking, but they seem less coherent..");

  cLarsHaikola.Say("The mistress of cruelty cannot be slain until the white hare lies in blood.");
  cDanWolgers.Say("What?");
  cErnstBillgren.Say("Lost control, fell apart, the wole damn genealogy went berserk!");
  cLarsHaikola.Say("I don't think I want to hear anymore about it.");
  cErnstBillgren.Say("It was the bladder that set it off.");
  cDanWolgers.Say("The bladder? What, what bladder?");
  cErnstBillgren.Say("Hieronymus Bosch. Medieval Doedelzak with the face!");
  cDanWolgers.Say("GHASTLY THING!");
  cErnstBillgren.Say("Cornered the Dali!");
  cLarsHaikola.Say("The Dali?");
  cDanWolgers.Say("Dali! The Great Masturbator!");
  cErnstBillgren.Say("Call him pretentious...");
  cLarsHaikola.Say("For God's sake...");
  cErnstBillgren.Say("...the Miro burst the bladder with one of its sharp pointy things.");
  cLarsHaikola.Say("Lascaux fighting cartoons. Strindberg eaten by an aztec codex.");
  cDanWolgers.Say("Mohammad drawings ambushed by rosicrucians!");
  cErnstBillgren.Say("The Phoenix SMASHED the Damien Hirst!");
  cErnstBillgren.Say("FORMALDEHYDE EVERYWHERE!");
  cLarsHaikola.Say("Will you shut up?!");

  blastofirregularity = true;
}
}


And this is in the room script:

Code: AGS


function ChangeValueOfJibberish(){
  if (blastofirregularity == true)
  JibberishFinished = true;
}

function room_RepExec()
{
ChangeValueOfJibberish();

if (JibberishFinished == true)
    {   if (IsTimerExpired(2))
       {
  cErnstBillgren.SayBackground("I have so much money it's embarrassing");
  SetTimer(2,  120);
       }
 }
 }



Timers are set in Room Load....There's only one sentence there because....I can't even get that one to work. Ideally, all the characters will have their own timers and speak over one another.....What did I do wrong?

Cheers

L

Crimson Wizard

Quote
Using the sayBackround command makes it so they all speak at the same time and only the last line

This is quite a basic mistake. SayBackground command does not block further script, therefore next command is executed right away. Since there may be only one saying per character at a time, the next SayBackground overrides previous one and finally only last lines are shown.

Quote
I've also tried to use timers, where I call a function in repeatedly execute to make sure the conversation is over, and then IsTimerExpired and so on....The thing is, sometimes it works (typically with short sentences... like, three words) and sometimes it freezes up and the text in the saybackground won't leave the screen.
Well, using timers in room_RepExec sounds like a  much better idea. Perhaps you just had some mistakes there?
Basically you need to run the timer after each background saying until all phrases are done.
For example:
Code: ags

int JibberishCount;
bool JibberishState;

function iAstonishingBlast_Talk()
{
  if (cEgo.Room == 37 && (Game.DoOnceOnly("jibberish")))
  {
     Display("The voices keep talking, but they seem less coherent..");
     JibberishCount = 0;
     JibberishState = true;
     SetTimer(2, 120);
  }
}

function DoJibberish()
{
  if (IsTimerExpired(2))
  {
    JibberishCount++;
    if (JibberishCount == 1)
       cLarsHaikola.Say("The mistress of cruelty cannot be slain until the white hare lies in blood.");
    else if (JibberishCount == 2)
       cDanWolgers.Say("What?");
    else if (JibberishCount == 3)
       cErnstBillgren.Say("Lost control, fell apart, the wole damn genealogy went berserk!");
    else ......
    <.....>
    else
       JibberishState = false; // done talking

    if (JibberishState)
    {
       SetTimer(2, 120);
    }
  }
}

function room_RepExec()
{
   if (JibberishState)
   {
      DoJibberish();
   }
}

itsnotwhatyouthink

That is GOLD! Problem sorted, thank you so much :)

Andail

Off-topic:
Hehe, loving those characters, and the dialogue... Hope to see more of this!

SMF spam blocked by CleanTalk