Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: randypana on Sat 06/07/2013 20:57:51

Title: making the gui
Post by: randypana on Sat 06/07/2013 20:57:51
hi i am making a gui and make a label, that I can do to change the word label such as: open door, and if I put something else: talking to elaine
Title: Re: making the gui
Post by: monkey0506 on Sat 06/07/2013 21:24:06
Code (ags) Select
// GlobalScript.asc

String GetCursorText(this Mouse*) // function to get the current cursor mode text
{
  if (this.Mode == eModeWalkto) return "Walk to"; // check cursor mode and return relevant text
  else if (this.Mode == eModeLookat) return "Look at";
  else if (this.Mode == eModeInteract) return "Use";
  else if (this.Mode == eModePickup) return "Pick up";
  else if (this.Mode == eModeTalkto) return "Talk to";
  else if (this.Mode == eModeUseinv)
  {
    // if mode is Useinv, make sure player has valid active inventory
    if ((player.ActiveInventory != null) && (!String.IsNullOrEmpty(player.ActiveInventory.Name)) return String.Format("Use %s on", player.ActiveInventory.Name);
    else return "Use";
  }
  else return null;
}

function repeatedly_execute()
{
  String loc = Game.GetLocationName(mouse.x, mouse.y); // location name
  String cur = mouse.GetCursorText(); // get cursor text (as defined above)
  if (cur == null) // cursor invalid, no text given
  {
    if (String.IsNullOrEmpty(loc)) lblLocation.Text = ""; // if location also is unnamed, blank out label text
  }
  else if (String.IsNullOrEmpty(loc)) lblLocation.Text = cur; // if cursor is valid but location unnamed, set label to cursor text
  else lblLocation.Text = String.Format("%s %s", cur, loc); // else both are valid, assign to label
}
Title: Re: making the gui
Post by: randypana on Sat 06/07/2013 21:39:50
Quote from: monkey_05_06 on Sat 06/07/2013 21:24:06
Code (ags) Select
// GlobalScript.asc

String GetCursorText(this Mouse*) // function to get the current cursor mode text
{
  if (this.Mode == eModeWalkto) return "Walk to"; // check cursor mode and return relevant text
  else if (this.Mode == eModeLookat) return "Look at";
  else if (this.Mode == eModeInteract) return "Use";
  else if (this.Mode == eModePickup) return "Pick up";
  else if (this.Mode == eModeTalkto) return "Talk to";
  else if (this.Mode == eModeUseinv)
  {
    // if mode is Useinv, make sure player has valid active inventory
    if ((player.ActiveInventory != null) && (!String.IsNullOrEmpty(player.ActiveInventory.Name)) return String.Format("Use %s on", player.ActiveInventory.Name);
    else return "Use";
  }
  else return null;
}

function repeatedly_execute()
{
  String loc = Game.GetLocationName(mouse.x, mouse.y); // location name
  String cur = mouse.GetCursorText(); // get cursor text (as defined above)
  if (cur == null) // cursor invalid, no text given
  {
    if (String.IsNullOrEmpty(loc)) lblLocation.Text = ""; // if location also is unnamed, blank out label text
  }
  else if (String.IsNullOrEmpty(loc)) lblLocation.Text = cur; // if cursor is valid but location unnamed, set label to cursor text
  else lblLocation.Text = String.Format("%s %s", cur, loc); // else both are valid, assign to label
}

thanks hope this is I need is, greetings ;-D
Title: Re: making the gui
Post by: Jaffles on Wed 10/07/2013 16:36:28
Thinking about putting something like this in a game I'm working on. Does this work on hotspots as well as objects/characters?
Title: Re: making the gui
Post by: Kitai on Wed 10/07/2013 17:51:31
Quote from: Jaffles on Wed 10/07/2013 16:36:28
Does this work on hotspots as well as objects/characters?
Yes it does (http://www.adventuregamestudio.co.uk/wiki/Game_/_Global_functions#Game.GetLocationName).
Title: Re: making the gui
Post by: monkey0506 on Wed 10/07/2013 19:43:23
Granted, it's a bit passive-aggressive on my part, posting the code without a single word. But this is one of the most commonly asked beginner questions. For more robust solutions you may want to take a look at the Description module, because that offers variant solutions as to how and where the text is displayed. The code snippet I provided should be enough to get you the basic idea, and it serves as a relatively simple introduction to the development process in AGS (because scripting is required). I even provided comments to help walk you through it. :P