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?
Have you tried something like:
/*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:
/*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);
}
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) {
/*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.
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
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...
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.
Oh...yeah...sorry about that... :-[ Thanks for spotting that Gilbot.
I tried to move that line but that didn't work because the character didn't say anything at all when i did that
Post the script that you currently have for this. Please? It would help.
#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
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
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
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
Tried that too, didn't work. Grrr maybe i should just give it up hehe
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?
Finally I got it working, thanks everyone :D
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 ;).
haha he's drunk...he doesn't know that ;)
LOL. Glad it's working. Now mind telling us how you fixed it, so others will know? :)
oh of course.
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(6);
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...");
else if (rand == 3) StrCopy(text, "I feel like I'm going to puke...");
else if (rand == 4) StrCopy(text, "Where am I?...");
else if (rand == 5) StrCopy(text, "Hic...");
else if (rand == 6) StrCopy(text, "Who are you?...");
speech = cOaf.SayBackground(text);
}
}
else {
string text;
int rand = Random(6);
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...");
else if (rand == 3) StrCopy(text, "I feel like I'm going to puke...");
else if (rand == 4) StrCopy(text, "Where am I?...");
else if (rand == 5) StrCopy(text, "Hic...");
else if (rand == 6) StrCopy(text, "Who are you?...");
speech = cOaf.SayBackground(text); }
}
#sectionend room_a // DO NOT EDIT OR REMOVE THIS LINE
Just to clarify on the indentation, the else statement only gets run if speech is null...not if it's Valid. You should use comment tags to make sure that your indentation is not messed up. Unless of course that is the same indentation that you used, in which case you should indent better because the way you have it indented it looks like the else statement is run if speech is Valid, not null.