Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Bobsy on Sun 11/07/2010 11:37:49

Title: character.say - a line chosen from random [SOLVED]
Post by: Bobsy on Sun 11/07/2010 11:37:49
Brain no-worky today.

In looking at an inventory item, I want to choose a random line to say from a selection of about 10. I know it's very simple and the solution will suddenly seem simple when I see it, but...
Title: Re: character.say - a line chosen from random
Post by: Sslaxx on Sun 11/07/2010 11:46:52
I dunno, but maybe something like:
String ThingsToSay [10];
ThingsToSay [1]= "a";
...
character.Say (ThingsToSay [(Random (9)+1)];
Title: Re: character.say - a line chosen from random
Post by: Bobsy on Sun 11/07/2010 13:49:01
I engaged my brainlobes and came up with this rather simpler system:
{
  int cardran=Random(9);
  cNarr.Say("My card. It read:");
  cNarr.Say("'Sir Alfred D. Venture.'");
  if (cardran==0) cNarr.Say("'The D is for DANGER!'");
  else if (cardran==1) cNarr.Say("'The D is for DEBONAIR!'");
  else if (cardran==2) cNarr.Say("'The D is for DASHING!'");
  else if (cardran==3) cNarr.Say("'The D is for DECISIVE!'");
  else if (cardran==4) cNarr.Say("'The D is for DYNAMIC!'");
  else if (cardran==5) cNarr.Say("'The D is for DAPPER!'");
  else if (cardran==6) cNarr.Say("'The D is for DANDY!'");
  else if (cardran==7) cNarr.Say("'The D is for DEVILISHLY HANDSOME!'");
  else if (cardran==8) cNarr.Say("'The D is for DAMN FINE FELLOW!'");
  else
  {
    cNarr.Say("'The D is for DONALD!'");
    player.Say("Wait, it's not supposed to say that.");
  }
}
Title: Re: character.say - a line chosen from random
Post by: Sslaxx on Sun 11/07/2010 14:02:58
Quote from: Bobsy on Sun 11/07/2010 13:49:01
I engaged my brainlobes and came up with this rather simpler system:
{
  int cardran=Random(9);
  cNarr.Say("My card. It read:");
  cNarr.Say("'Sir Alfred D. Venture.'");
  if (cardran==0) cNarr.Say("'The D is for DANGER!'");
  else if (cardran==1) cNarr.Say("'The D is for DEBONAIR!'");
  else if (cardran==2) cNarr.Say("'The D is for DASHING!'");
  else if (cardran==3) cNarr.Say("'The D is for DECISIVE!'");
  else if (cardran==4) cNarr.Say("'The D is for DYNAMIC!'");
  else if (cardran==5) cNarr.Say("'The D is for DAPPER!'");
  else if (cardran==6) cNarr.Say("'The D is for DANDY!'");
  else if (cardran==7) cNarr.Say("'The D is for DEVILISHLY HANDSOME!'");
  else if (cardran==8) cNarr.Say("'The D is for DAMN FINE FELLOW!'");
  else
  {
    cNarr.Say("'The D is for DONALD!'");
    player.Say("Wait, it's not supposed to say that.");
  }
}
AGS could so do with a "switch...case" statement.
Title: Re: character.say - a line chosen from random [SOLVED]
Post by: Gilbert on Mon 12/07/2010 01:41:06
Quote from: Sslaxx on Sun 11/07/2010 14:02:58
AGS could so do with a "switch...case" statement.
Beware that this may make people misinterpret as 'AGS can do so...'. :P
Title: Re: character.say - a line chosen from random [SOLVED]
Post by: Babar on Mon 12/07/2010 08:14:41
This is a thing I was wondering about... I like having a choice of several random responses for many things in game, even default responses. I used to be able to do this with the global variables (when they were accessible by their numbers), but just generating a random number.

I suppose now the only solution is to type up a huge list of responses into a string array in the global script?
Title: Re: character.say - a line chosen from random [SOLVED]
Post by: Calin Leafshade on Mon 12/07/2010 08:21:45
or store them in a file... although that may be travelling down the road of diminishing returns.
Title: Re: character.say - a line chosen from random [SOLVED]
Post by: GarageGothic on Mon 12/07/2010 08:59:38
You could also write all responses in a single String with some kind of separator symbol in-between, and then have a function that parses the String before displaying one of the responses. I think that's how the MultiResponse module (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27947.0) does it. (Or if you're not stubborn about writing your own code like me, just use the module :)).
Title: Re: character.say - a line chosen from random [SOLVED]
Post by: Knox on Mon 12/07/2010 17:35:56
Dont know if this helps but I just did what you did, pretty much, by using Random...then typing out all the possible responses...I did an unhandled script for inventory item clicks, and normal gameplay clicks (for hotspots, characters, objects)...this is what my inventory items unhandled script looks like


void unhandled_InventoryMenuResponses(InventoryItem *overItem)
{
  unhandledResponse_Inv = Random(5);
  //EXAMINE INVENTORY ITEMS 1/4
  if (mouse.Mode == eModeExamine)
  {
    if (unhandledResponse_Inv == 0) Display("Unhandled response...rand00 Examine item: %s", overItem.Name);
    else if (unhandledResponse_Inv == 1) Display("Unhandled response...rand01 Examine item: %s", overItem.Name);
    else if (unhandledResponse_Inv == 2) Display("Unhandled response...rand02 Examine item: %s", overItem.Name);
    else if (unhandledResponse_Inv == 3) Display("Unhandled response...rand03 Examine item: %s", overItem.Name);
    else if (unhandledResponse_Inv == 4) Display("Unhandled response...rand04 Examine item: %s", overItem.Name);
    else if (unhandledResponse_Inv == 5) Display("Unhandled response...rand05 Examine item: %s", overItem.Name);
  }
  //MANIPULATE INVENTORY ITEMS 2/4
  else if (mouse.Mode == eModeManipInv)
  {
etc.....
}


Im almost 95.4% sure people here could write that better, but hey, it works!