Dynamically altering displayed speech text? [SOLVED]

Started by jusamus, Sat 29/09/2007 11:43:22

Previous topic - Next topic

jusamus

I wonder if it's possible to somehow dynamically append flavor to spoken text?
Eg. if a character is drunk, append h after every s (for example: "Ishn't it nice"),
or something else like that.

It would be nice, but I doubt it's doable.

Rui 'Trovatore' Pires

Doable, but it might wield random results. It's "moduable", even.

For starters, you'd need to make your own Talk function. Then you'd check to see if the character was drunk (variable). If so, then scan the string you've passed for any "s" (use while loops for a single string). When you find one (using a function which returns a string's character, I disremember the name) then insert an "h" just after the returned index in the string (which id's where in the string the "s" was). Implement each letter-adding into the new string you'll use to call AGS' "Say" function, and call the function.

You can also randomize it so it doesn't happen with ALL "s".

Doable, but might give some wild results. If anything it wrong with my logic, I'd welcome corrections.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

jusamus

That sounds like good news to me! :) I've fiddled with AGS from time to time, and ATM using it to create a reference demo of a game we are making for a school project. I'm making progress in scripting, but far from being an expert. So, if I create my own Talk-function, it can be used in the same way as the normal Say-function? The character in the game is already somewhat scripted to react differently at different drunk-states (value taken from a global int) so the drunk-talk would add a great deal to the "realism".

You can check out the starting room demo at http://koti.mbnet.fi/tulisalo/Compiled.zip if you like. It only has one puzzle at the moment, but as I said, this is still a reference demo.

Rui 'Trovatore' Pires

Well, this isn't exactly very very very advanced stuff, but IMO it might just be easier to take advantage of the checks already in, and as he reacts differently add the different message...
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

jusamus

Yes, I considered that, but that's a lot of typing / copy-pasteing as the drunkedness is a central feature, not a short-term effect :D.. so I'll try making it dynamical, saves a lot of work in the future!

Thanks for the tips!

jusamus

#5
Okay, I figured a real easy way to do this, thanks to Trov:
Code: ags

function Talk(String txt) { // drunk-speech
	int i = 0,index = 0;
	String temp = "";
	if ( GetGlobalInt(2) > 80 ) {
		while ( i < txt.Length ) {
			if ( txt.Chars[i] == 's' && txt.Chars[i+1] != 's' && txt.Chars[i-1] != 's' && txt.Chars[i+1] != 'h') {
				temp = temp.Append(txt.Substring(index, (i-index)+1));
				temp = temp.Append("h");
				index = i+1;
			}
			if ( txt.Chars[i] == ' ' && Random(5) == Random(5) ) {
				temp = temp.Append(txt.Substring(index, (i-index)+1));
				temp = temp.Append("*hic* ");
				index = i+1;
			}
			i++;
		}
		temp = temp.Append(txt.Substring(index, (i-index)+1));
	}
	else temp = txt;
	character[EGO].Say(temp);

}


I just replaced all character[EGO].Say("blah") to Talk("blah"), that's it.

It may not *hic* be the mosht elegant *hic* way, but doesh the trick! :)

SMF spam blocked by CleanTalk