Hi, I was trying to create my own function to write the speech on a gui, this function works perfect drawing the text on the gui, but the only problem is that the player can walk while and interact while the speech is draw in the gui (something like SayBackground) and the speech can't be skipped. Searching in the help menu of ags I found that you can use GUI.AsTextWindow but I can't get to work it. I use the thumbleweed script and the AGS version is the latest version.
I tried to add a timer to "Block" the interactions while the speech is on screen but doesn't work.
// new module script
DynamicSprite*messagetext;
#define GWIDTH 300
#define GHEIGHT 30
#define GTIMER 1
#define TEST 1
void MySay(this Character*, String message) {
if (messagetext == null) messagetext = DynamicSprite.Create(GWIDTH, GHEIGHT);
DrawingSurface*ds = messagetext.GetDrawingSurface();
ds.Clear();
ds.DrawingColor = this.SpeechColor;
int w = GWIDTH - 20;
int wt = GetTextWidth(message, Game.SpeechFont) + 5;
if (wt < w) w = wt;
gSpeech.Width = w + 20;
gSpeech.X = (Screen.Width - w - 20) / 2;
int y = (GHEIGHT - GetTextHeight(message, Game.SpeechFont, w)) / 2;
ds.DrawStringWrapped(10, y, w, Game.SpeechFont, eAlignCenter, message);
ds.Release();
gSpeech.BackgroundGraphic = messagetext.Graphic;
gSpeech.Visible = true;
SetTimer(TEST, (message.Length / game.text_speed));
SetTimer(GTIMER, ((message.Length / game.text_speed) + 1) * GetGameSpeed());
}
function repeatedly_execute() { //this was supposed to work like "Blocking" but don't work
if (gSpeech.Visible) {
Wait(TEST);
}
}
function repeatedly_execute_always() {
GUI*g = gSpeech;
gBlack.Visible = g.Visible;
if (g.Visible) {
gBlack.SetPosition(g.X, g.Y);
gBlack.SetSize(g.Width, g.Height);
}
if (IsTimerExpired(GTIMER)) gSpeech.Visible = false;
}
I'm pretty sure you can simply Wait(((message.Length / game.text_speed) + 1) * GetGameSpeed()); at the end of the MySay function?
Oh I didn't know that will work, thanks. But now I can't get how to make the speech skippable
Use WaitMouseKey() instead.
I tried that but nothing happen
Can you be a bit more specific? And maybe post the code you're currently using?
The code is this:
// new module script
DynamicSprite*messagetext;
#define GWIDTH 300
#define GHEIGHT 30
#define GTIMER 1
void MySay(this Character*, String message) {
if (messagetext == null) messagetext = DynamicSprite.Create(GWIDTH, GHEIGHT);
DrawingSurface*ds = messagetext.GetDrawingSurface();
ds.Clear();
ds.DrawingColor = this.SpeechColor;
int w = GWIDTH - 20;
int wt = GetTextWidth(message, Game.SpeechFont) + 5;
if (wt < w) w = wt;
gSpeech.Width = w + 20;
gSpeech.X = (Screen.Width - w - 20) / 2;
int y = (GHEIGHT - GetTextHeight(message, Game.SpeechFont, w)) / 2;
ds.DrawStringWrapped(10, y, w, Game.SpeechFont, eAlignCenter, message);
ds.Release();
gSpeech.BackgroundGraphic = messagetext.Graphic;
gSpeech.Visible = true;
SetTimer(GTIMER, ((message.Length / game.text_speed) + 1) * GetGameSpeed());
WaitMouseKey(((message.Length / game.text_speed) + 1) * GetGameSpeed()); //I added this but doesn't work
}
function repeatedly_execute_always() {
GUI*g = gSpeech;
gBlack.Visible = g.Visible;
if (g.Visible) {
gBlack.SetPosition(g.X, g.Y);
gBlack.SetSize(g.Width, g.Height);
}
if (IsTimerExpired(GTIMER)) gSpeech.Visible = false;
}
Remove the timer code, and again, please describe how the code fails.
"Doesn't work" is a useless problem description. We know it doesn't work.
Oh, sorry my bad. What I mean with that is the code works fine if I use only the wait function, the speech draws and I only can interact when it finishes, but if I use the waitmousekey the speech draws fine, I can interact but the speech is still draw on the screen (doesn't skipped with the click).
I think you are missing "gSpeech.Visible = false;" after WaitMouseKey.
(and remove "if (IsTimerExpired(GTIMER)) gSpeech.Visible = false;" from rep-exec of course)
The blocking speech algorithm is simple:
* display speech
* call wait
* hide speech
Ooooh thank you so much! It worked perfectly now.