character.say - a line chosen from random [SOLVED]

Started by Bobsy, Sun 11/07/2010 11:37:49

Previous topic - Next topic

Bobsy

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...

Sslaxx

#1
I dunno, but maybe something like:
Code: ags
String ThingsToSay [10];
ThingsToSay [1]= "a";
...
character.Say (ThingsToSay [(Random (9)+1)];
Stuart "Sslaxx" Moore.

Bobsy

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

Sslaxx

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.
Stuart "Sslaxx" Moore.

Gilbert

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

Babar

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?
The ultimate Professional Amateur

Now, with his very own game: Alien Time Zone

Calin Leafshade

or store them in a file... although that may be travelling down the road of diminishing returns.

GarageGothic

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 does it. (Or if you're not stubborn about writing your own code like me, just use the module :)).

Knox

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

Code: ags

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!
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk