Timer Label in GUI [SOLVED]

Started by LupaShiva, Fri 27/08/2010 13:45:05

Previous topic - Next topic

LupaShiva

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

Lt. Smash

#1
First of all you don't need String.Format() if you don't use any variables in the output.
So you can just use:
Code: ags
GUITexto.Text = "New item taken.";


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



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


And then just call this after you've changed the label text:
Code: ags
SetTimer(1, (5*40)); // 40 loops per second

Khris

Exactly, or use a custom function:

Code: ags
// 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:

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


or with a different timeout:

Code: ags
  Message(String.Format("%s taken.", iBox.Name), 10);


LupaShiva

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
}

tzachs

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...

LupaShiva

Sorry my fault im not understanding where is to put that script, its still put in the hotspot script or in another place? Sorry

LupaShiva

Oh awesome already did it, thak you  ;)

Khris

Code: ags
GUITexto.Text = ("New item taken.");


You don't need the brackets, btw.

LupaShiva


SMF spam blocked by CleanTalk