Displaying a returned String in a dialog, say and display **SOLVED**

Started by Knox, Fri 21/05/2010 15:59:59

Previous topic - Next topic

Knox

Ive got a game setting that turns swearing on or off. If the mode is on, you see swearing in the text and dialog. I saved this setting in a bool and by default its true:
Code: ags
bool matureLanguage = true;


I wrote this String, if matureLanguage is false, instead of the inputted swear word string, display a "censor" of characters:
Code: ags

String swear(String sSwearWord)
{
  if (matureLanguage == true)
  {
     return sSwearWord;
  }
  else
  {
    sSwearWord = "$%#@";
    return sSwearWord;
  }
}


However, I dont know exactly how to display this (with Display, Say or in a dialog). This was my best attempt:

Code: ags
    Display("Go %d yourself.", String swear(Fuck)); 


How would I display this in dialog, say command or with display?

--All that is necessary for evil to triumph is for good men to do nothing.

Ryan Timothy B

You were very close.  You just have to do this (which also works for character.Say):
Code: ags
Display("Go %s yourself.", swear("Fuck"));



Also you don't have to store the censored word into a string variable before returning it, you can simply just return the string itself:
Code: ags

String swear(String sSwearWord)
{
  if (matureLanguage == true)
  {
    return sSwearWord;
  }
  else
  {
    return "$%#@";
  }
}

Knox

Hi Ryan!

Thanks for your help, I got it working now! Man, I was sooo close...Im slowly learning :P

Now, one last question:

This could create a problem when I activate speech, since the text can be censored but the same audio file with swearing will be played. I guess I can use "if/ else", but then I would have to write the dialog line twice and defeats the purpose of my above script. Is there a way to make the call to the audio file a variable aswell? Something like:

Code: ags

function swearAudio(int swearFile)
{
  if matureLanguage == true
  {
    return swearFile; //which would be file #2 (cEGO2.wav)...the line with swearing
  }
  else
  {
    return 1; //which would be file #1 (cEGO1.wav)...the line with a "Beep" sound instead
  }
}


This is normally how we'd write the line with the audio file for speech:
Code: ags

cEgo.Say (&2 "Go %s yourself.", swear("Fuck"));


Is it possible to make the "&2" audio file call a variable? (the number 2 here would reflect cEgo2.wav)...something like:
Code: ags

cEgo.Say("%d "Go %s yourself.", swearAudio(2), swear("Fuck"));

--All that is necessary for evil to triumph is for good men to do nothing.

Khris

This should do it:
  cEgo.Say("&%d Go %s yourself.", swearAudio(2), swear("Fuck"));

The most convenient way would be to use two consecutive audio files; that way you can use this:
Code: ags
int swearAudio(int x) {
  if (matureLanguage) return x;
  return x+1;
}

Knox

--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk