Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: LupaShiva on Fri 27/08/2010 13:45:05

Title: Timer Label in GUI [SOLVED]
Post by: LupaShiva on Fri 27/08/2010 13:45:05
Hi, i already searhed the forum but cant find a good help for my doubt, i have a label in a GUI that display a message depending of whatI'm doing, so if i get a a item it says "New item taken" if i discovered a new place "New place discovered" i already got that to work with the script

GUITexto.Text = String.Format ("New item taken.");

For example, but now i want it to dissaper in 5 seconds and i cant do it, i know ill problably have to do something like

GUITexto.Text = String.Format ("");

but cant activate the timer, how can i do it?

Thank you
Title: Re: Timer Label in GUI
Post by: Lt. Smash on Fri 27/08/2010 15:38:36
First of all you don't need String.Format() if you don't use any variables in the output.
So you can just use:
GUITexto.Text = "New item taken.";

But use String.Format, if f.e. you want to display the items name.
GUITexto.Text = String.Format("%s taken.", item.name);


To answer your question. You need to put this into repeatedly execute:
if(IsTimerExpired(1)) {
 GUITexto.Text = "";
}


And then just call this after you've changed the label text:
SetTimer(1, (5*40)); // 40 loops per second
Title: Re: Timer Label in GUI
Post by: Khris on Sat 28/08/2010 12:57:23
Exactly, or use a custom function:

// header (global.ash)

import void Message(String text, int timeout = 5);  // default: 5 seconds

// global script (global.asc)

void Message(String text, int timeout) {
  GUITexto.Text = text;
  SetTimer(1, timeout*GetGameSpeed());
}


Call it like this:

  Message(String.Format("%s taken.", iBox.Name));

or with a different timeout:

  Message(String.Format("%s taken.", iBox.Name), 10);
Title: Re: Timer Label in GUI
Post by: LupaShiva on Sat 28/08/2010 15:27:33
Well Thank you for the help but it doesnt work, prob im doing something wrong but dont know what, i used:

function hSacoLixo_Interact() //name of the hotspot where is the object
{
  if (cJake.HasInventory(iPills)) //if the char already got the object
  cJake.Say("There's nothing more there.");
  else
 
  cJake.Say ("I found some Sleeping pills.");// if the char doesnt have the object
  GUITexto.Text = ("New item taken."); // text appear in GUIlabel
 
  SetTimer(1, (5*40)); //i set the timer
  if(IsTimerExpired(1)) { //the timer expires
  GUITexto.Text = ""; //and here the text doenst appear dont know why
}

  cJake.AddInventory (iPills); //here i add the inventory
  GiveScore(5);  //here i give score
}
Title: Re: Timer Label in GUI
Post by: tzachs on Sat 28/08/2010 15:36:36
You missed the part when they said that the "if (IsTimeExpired)" line should be in the repeatedly execute function, not in the hSacoLixo_Interact function...
Title: Re: Timer Label in GUI
Post by: LupaShiva on Sat 28/08/2010 15:40:24
Sorry my fault im not understanding where is to put that script, its still put in the hotspot script or in another place? Sorry
Title: Re: Timer Label in GUI
Post by: LupaShiva on Sat 28/08/2010 15:42:29
Oh awesome already did it, thak you  ;)
Title: Re: Timer Label in GUI
Post by: Khris on Sat 28/08/2010 17:17:03
GUITexto.Text = ("New item taken.");

You don't need the brackets, btw.
Title: Re: Timer Label in GUI
Post by: LupaShiva on Sat 28/08/2010 19:02:11
Ok thank you again  ;)