Background speech [SOLVED]

Started by Mouth for war, Tue 02/08/2005 20:24:56

Previous topic - Next topic

Mouth for war

I have aÃ,  drunk character and i want him to say a few lines to himself like "owww"...."My head really hurts" etc.Ã,  without pausing the game.Ã,  I've been searching in this forum for help and I've found a few things but when i try to use that stuff I only get error messages in the script...anyone who can tell me exactly how to do?
mass genocide is the most exhausting activity one can engage in, next to soccer

monkey0506

Have you tried something like:

Code: ags
/*repeatedly_execute*/
Overlay* speech;
if (!speech.Valid) speech = cCharname.SayBackground("Ow...my head hurts...");


I've never worked with Overlays but I think that should work.  Of course you would want more than one line of text so you could use something like:

Code: ags
/*repeatedly_execute*/
Overlay* speech;
if (!speech.Valid) {
  string text;
  int rand = Random(2);
  if (rand == 0) StrCopy(text, "Oww...");
  else if (rand == 1) StrCopy(text, "My head hurts...");
  else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
  speech = cCharname.SayBackground(text);
  }

Mouth for war

I tried it and when i test the game there are no errors but when i enter the room where i want it to happen the game ends and i get an error message saying "an internal error has occured"
Error: run_text_script1: error -6 running function 'room_a':
Error null pointer referenced
in room 4 script (line 7)

Line 7 is if (!speech.Valid) {
mass genocide is the most exhausting activity one can engage in, next to soccer

monkey0506

Code: ags
/*repeatedly_execute*/
Overlay* speech;
if (speech != null) {
  if (!speech.Valid) {
    string text;
    int rand = Random(2);
    if (rand == 0) StrCopy(text, "Oww...");
    else if (rand == 1) StrCopy(text, "My head hurts...");
    else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
    speech = cCharname.SayBackground(text);
    }
  }
else {
  string text;
  int rand = Random(2);
  if (rand == 0) StrCopy(text, "Oww...");
  else if (rand == 1) StrCopy(text, "My head hurts...");
  else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
  speech = cCharname.SayBackground(text);
  }


This will initialize the Overlay the first time it runs (it will display text and store it in Overlay* speech.  Before I didn't check if it was null, and if it's null then it doesn't point to anything (hence there is no Valid property).  Sorry about that.

Mouth for war

Thanks that worked BUT...you can barely see what he's saying cause every line he says only stays onscreen for about 0000000.1 seconds
mass genocide is the most exhausting activity one can engage in, next to soccer

monkey0506

Well...like I said I have never worked with Overlays and stuff.  The manual said that with SayBackground the speech would remain for a set amount of time...I think.  Read in the manual under Character.SayBackground().  I'm sorry but I think this is my limit on help with this problem for now.  Sorry.  I tried to help...

Gilbert

The problem is that you put:

Overlay* speech;

inside of repeatedly execute, so its content will be continuously destroyed every gameloop.
Move that line out of teh function and put it on top of the script and try again.

monkey0506

Oh...yeah...sorry about that... :-[  Thanks for spotting that Gilbot.

Mouth for war

I tried to move that line but that didn't work because the character didn't say anything at all when i did that
mass genocide is the most exhausting activity one can engage in, next to soccer

monkey0506

Post the script that you currently have for this.  Please?  It would help.

Mouth for war


#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for Room: Repeatedly execute
Overlay* speech;
if (speech != null) {
  if (!speech.Valid) {
    string text;
    int rand = Random(100);
    if (rand == 0) StrCopy(text, "Oww...");
    else if (rand == 1) StrCopy(text, "My head hurts...");
    else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
    speech = cOaf.SayBackground(text);
    }
  }
else {
  string text;
  int rand = Random(100);
  if (rand == 0) StrCopy(text, "Oww...");
  else if (rand == 1) StrCopy(text, "My head hurts...");
  else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
  speech = cOaf.SayBackground(text);
  }
}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE
mass genocide is the most exhausting activity one can engage in, next to soccer

Gilbert

As I mentioned before, move that Overlay* speech; line outside of the repeatedly_execute() function, put it on TOP of the whole script.

Something like:

On top of script:
Overlay* speech;

In function repeatedly_execute():
#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
Ã,  // script for Room: Repeatedly execute

if (speech != null) {
Ã,  if (!speech.Valid) {
Ã,  Ã,  string text;
Ã,  Ã,  int rand = Random(100);
Ã,  Ã,  if (rand == 0) StrCopy(text, "Oww...");
Ã,  Ã,  else if (rand == 1) StrCopy(text, "My head hurts...");
Ã,  Ã,  else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
Ã,  Ã,  speech = cOaf.SayBackground(text);
Ã,  Ã,  }
Ã,  }
else {
Ã,  string text;
Ã,  int rand = Random(100);
Ã,  if (rand == 0) StrCopy(text, "Oww...");
Ã,  else if (rand == 1) StrCopy(text, "My head hurts...");
Ã,  else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
Ã,  speech = cOaf.SayBackground(text);
Ã,  }
}
#sectionend room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE

Mouth for war

ok now it looks like this but now it won't work at all. Sorry for being a pain in the butt hehe...but i'm a real newbie

Overlay* speech;
#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {  // script for Room: Repeatedly execute
if (speech != null) { 
if (!speech.Valid) {   
string text;
int rand = Random(100);
if (rand == 0) StrCopy(text, "Oww...");
else if (rand == 1) StrCopy(text, "My head hurts...");
else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
speech = cOaf.SayBackground(text);
    }
}
else {
  string text;
  int rand = Random(100);
  if (rand == 0) StrCopy(text, "Oww...");
  else if (rand == 1) StrCopy(text, "My head hurts...");
  else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
  speech = cOaf.SayBackground(text);  }
}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE

mass genocide is the most exhausting activity one can engage in, next to soccer

Gilbert

Try lowering the random value, currently, there's only a 3 out of 100 chance that he'll say something.

Overlay* speech;
#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {Ã,  // script for Room: Repeatedly execute
Ã,  if (speech != null) {Ã,  
Ã,  Ã,  if (!speech.Valid) {Ã,  Ã,  
Ã,  Ã,  Ã,  string text;
Ã,  Ã,  Ã,  int rand = Random(10);
Ã,  Ã,  Ã,  if (rand == 0) StrCopy(text, "Oww...");
Ã,  Ã,  Ã,  Ã,  else if (rand == 1) StrCopy(text, "My head hurts...");
Ã,  Ã,  Ã,  Ã,  else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
Ã,  Ã,  Ã,  Ã,  speech = cOaf.SayBackground(text);
Ã,  Ã, Ã,  Ã, }
Ã,  } else {
Ã,  Ã,  string text;
Ã, Ã,  Ã, int rand = Random(10);
Ã,  Ã,  if (rand == 0) StrCopy(text, "Oww...");
Ã,  Ã,  Ã,  else if (rand == 1) StrCopy(text, "My head hurts...");
Ã,  Ã,  else if (rand == 2) StrCopy(text, "I shouldn't have drank that last beer...");
Ã, Ã,  Ã, speech = cOaf.SayBackground(text);Ã,  }
}
#sectionend room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE

Mouth for war

Tried that too, didn't work. Grrr maybe i should just give it up hehe
mass genocide is the most exhausting activity one can engage in, next to soccer

monkey0506

Maybe you should change it to Random(2) just to be sure that it is the randomization causing no message to be displayed and not the script?

Mouth for war

Finally I got it working, thanks everyone :D
mass genocide is the most exhausting activity one can engage in, next to soccer

The Ivy

Not to be picky or anything, but the correct grammar for the last sentence would be "I shouldn't have drunk that last beer."Ã,  Unless it's part of the effect ;).

Mouth for war

haha he's drunk...he doesn't know that ;)
mass genocide is the most exhausting activity one can engage in, next to soccer

TerranRich

LOL. Glad it's working. Now mind telling us how you fixed it, so others will know? :)
Status: Trying to come up with some ideas...

SMF spam blocked by CleanTalk