Implementing a Lengthy Background Dialogue

Started by GoToHellDave, Mon 05/11/2012 12:13:20

Previous topic - Next topic

GoToHellDave

Hi.

I'm currently trying to make a group of NPCs have a lengthy conversation in the background which continues regardless of what the player does. I'm using a series of timers (being set off at different intervals) and triggering the dialogue at those intervals. Unfortunately, the engine only allows for a maximum of 20 timers and I require more than that. In the hopes of getting around this issue, I created an integer to which I add 1 each time a piece of dialogue is spoken and then use 'if' statements to check to see where the dialogue needs to go next. The code looks like this:

Code: AGS

// Create Timer
function room_Load()
{
  SetTimer(1, 120);
  SetTimer(2, 400);
  SetTimer(3, 550);
  SetTimer(4, 700);
  SetTimer(5, 900);
  SetTimer(6, 1050);
  SetTimer(7, 1250);
  SetTimer(8, 1550);
  SetTimer(9, 1800);
  SetTimer(10, 2050);
  SetTimer(11, 2300);
  SetTimer(12, 2600);
  SetTimer(13, 3000);
  SetTimer(14, 3200);
  SetTimer(15, 3400);
  SetTimer(16, 3600);
  SetTimer(17, 3800);
  SetTimer(18, 4150);
  SetTimer(19, 4400);
  SetTimer(20, 4600);
}

int check1 = 0;

// This code handles the NPCs talking amongst themselves in this room
function room_RepExec()
{
  if(IsTimerExpired(1))
  {
    if(check1 == 0)
    {
      cDiceNerd.SayBackground("bla bla bla");
      check1 ++;
    }
  }
  
  if(IsTimerExpired(1))
  {
    cWandNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(3))
  {
    cSwordNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(4))
  {
    cDiceNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(5))
  {
    cWandNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(6))
  {
    cSwordNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(7))
  {
    cDiceNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(8))
  {
    cWandNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(9))
  {
    cSwordNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(10))
  {
    cDiceNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(11))
  {
    cWandNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(12))
  {
    cSwordNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(13))
  {
    cDiceNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(14))
  {
    cWandNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(15))
  {
    cSwordNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(16))
  {
    cDiceNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(17))
  {
    cWandNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(18))
  {
    cSwordNerd.SayBackground("bla bla bla");
  }
  
  if(IsTimerExpired(19))
  {
    cDiceNerd.Say("bla bla bla");
  }
  
  if(IsTimerExpired(20))
  {
    cWandNerd.Say("bla bla bla");
    SetTimer(1, 120);
    check1 = 1;
  }
  
  if(IsTimerExpired(1))
  {
    if(check1 == 1)
    {
      cSwordNerd.SayBackground("bla bla bla");
      check1 = 2;
      SetTimer(1, 350);
    }
  }
  
  if(IsTimerExpired(1))
  {
    if(check1 == 2)
    {
      cDiceNerd.SayBackground("bla bla bla");
      check1 = 3;
      SetTimer(1, 220);
    }
  }
  
  if(IsTimerExpired(1))
  {
    if(check1 == 3)
    {
      cWandNerd.SayBackground("bla bla bla");
      check1 = 4;
      SetTimer(1, 170);
    }
  }
  
  if(IsTimerExpired(1))
  {
    if(check1 == 4)
    {
      cSwordNerd.SayBackground("bla bla bla");
      check1 = 5;
      SetTimer(1, 220);
    }
  }
  
  if(IsTimerExpired(1))
  {
    if(check1 == 5)
    {
      cDiceNerd.SayBackground("bla bla bla");
      check1 = 6;
      SetTimer(1, 320);
    }
  }
  
}


Unfortunately, the dialogue ceases after the 20th timer finishes and doesn't continue with the resetting of timer 1.

I'd imagine that I'm probably doing this in some extremely hard and impractical way that a real programmer would laugh at, so if you could point me int he right direction here I'd be extremely grateful.

Thanks in advance,

Ben.

geork

You can re-use the same timer whilst incrementing a variable to determine what part of the conversation should be played. For example:
Code: AGS

int turn;
function room_Load()
{
  SetTimer(1, 120);
  turn = 0; //if you want the dialog to start from the beginning every time the room is loaded, include this
}
function room_RepExec()
{
  if(IsTimerExpired(1))
  {
    if(turn == 0)
    {
      cDiceNerd.SayBackground("blah blah blah");
      setTimer(1, 280);
    }
    else if(turn == 1)
    {
      cWandNerd.SayBackground("blahhhh");
      setTimer(1, 150);
    }
    //etc etc.
    turn ++; //this is universal to all instances of dialog, so put here
  }
} 

This isn't the most efficient way of solving the problem, but it should work nicely :)

GoToHellDave

Thanks Geork, that worked a treat.

My mistake was not understanding the nature of the repeatedly execute function. Once you pointed out the use of '++' can effectively provide a means of counting it all became obvious.

SMF spam blocked by CleanTalk